Add Hunter NPC and Teleporter features with associated prefabs and effects

This commit is contained in:
2025-12-13 00:01:29 +01:00
parent c0fb207768
commit d8b0583fac
32 changed files with 823 additions and 217 deletions

View File

@@ -14,27 +14,27 @@ namespace Infrastructure.Unity
private float moveSpeed = 8f;
[SerializeField] private float maxVelocityChange = 10f;
[SerializeField] private float snapForce = 15f;
[Header("Controls")]
[SerializeField] private bool useCameraRelativeMovement = true;
[Header("Interaction")]
[SerializeField] private LayerMask tileLayer;
[SerializeField] private float groundCheckDistance = 1.5f;
[Self] [SerializeField] private Rigidbody rb;
[Self][SerializeField] private Rigidbody rb;
private InputSystem_Actions _actions;
private Vector2 _moveInput;
private Transform _camTransform;
public Rigidbody Rigidbody => rb;
public StatusManager Status { get; private set; }
private void OnEnable()
{
_actions.Player.Enable();
_actions.Player.Move.performed += OnMovePerformed;
_actions.Player.Move.canceled += OnMoveCanceled;
}
@@ -43,7 +43,7 @@ namespace Infrastructure.Unity
{
_actions.Player.Move.performed -= OnMovePerformed;
_actions.Player.Move.canceled -= OnMoveCanceled;
_actions.Player.Disable();
}
@@ -51,19 +51,22 @@ namespace Infrastructure.Unity
{
_actions = new InputSystem_Actions();
Status = new StatusManager();
if (Camera.main)
{
_camTransform = Camera.main.transform;
}
rb.freezeRotation = true;
rb.useGravity = true;
// RB gravity is controlled by capabilities
}
private void Update()
{
Status.Tick(Time.deltaTime);
// Apply Status logic
rb.useGravity = !Status.CurrentCapabilities.CanHover;
}
private void FixedUpdate()
@@ -79,7 +82,7 @@ namespace Infrastructure.Unity
var snapAxis = Vector3.zero;
Vector3 desiredDirection;
if (_moveInput.sqrMagnitude < 0.01f)
{
desiredDirection = Vector3.zero;
@@ -100,7 +103,7 @@ namespace Infrastructure.Unity
desiredDirection = new Vector3(_moveInput.x, 0, _moveInput.y).normalized;
}
if (desiredDirection.sqrMagnitude > 0.01f)
{
if (Mathf.Abs(desiredDirection.x) > Mathf.Abs(desiredDirection.z))
@@ -117,11 +120,11 @@ namespace Infrastructure.Unity
var velocity = rb.linearVelocity;
var velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0f;
rb.AddForce(velocityChange, ForceMode.VelocityChange);
if (snapAxis != Vector3.zero)
@@ -134,14 +137,14 @@ namespace Infrastructure.Unity
ApplySnapping(Vector3.forward);
}
}
private void ApplySnapping(Vector3 axis)
{
var currentPos = Vector3.Dot(transform.position, axis);
var targetPos = Mathf.Round(currentPos);
var diff = targetPos - currentPos;
var correction = axis * (diff * snapForce);
rb.AddForce(correction, ForceMode.Acceleration);
}
@@ -149,7 +152,7 @@ namespace Infrastructure.Unity
private void DetectGround()
{
if (!Status.CurrentCapabilities.CanTriggerDecay) return;
if (Physics.Raycast(transform.position, Vector3.down, out var hit, groundCheckDistance, tileLayer))
{
if (hit.collider.TryGetComponent<TileViewAdapter>(out var tileAdapter))