Refactor NPC behavior and teleportation logic; enhance tile material properties
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using KBCore.Refs;
|
||||
|
||||
@@ -12,28 +13,32 @@ namespace Infrastructure.Unity
|
||||
[Self] [SerializeField] private Rigidbody rb;
|
||||
|
||||
private PlayerController _target;
|
||||
private Action _onCaughtCallback;
|
||||
private Func<float> _timeDilationProvider;
|
||||
|
||||
public void Initialize(PlayerController target)
|
||||
public void Initialize(PlayerController target, Action onCaughtCallback, Func<float> timeDilationProvider)
|
||||
{
|
||||
_target = target;
|
||||
_onCaughtCallback = onCaughtCallback;
|
||||
_timeDilationProvider = timeDilationProvider;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (_target == null) return;
|
||||
if (!_target) return;
|
||||
|
||||
var dilation = _timeDilationProvider?.Invoke() ?? 1f;
|
||||
|
||||
if (IsGrounded())
|
||||
{
|
||||
var direction = (_target.transform.position - transform.position).normalized;
|
||||
// Flatten direction to avoid flying/digging
|
||||
direction.y = 0;
|
||||
direction.Normalize();
|
||||
|
||||
rb.MovePosition(rb.position + direction * (moveSpeed * Time.fixedDeltaTime));
|
||||
rb.MovePosition(rb.position + direction * (moveSpeed * dilation * Time.fixedDeltaTime));
|
||||
}
|
||||
|
||||
// Trigger tiles
|
||||
if (Physics.Raycast(transform.position, Vector3.down, out var hit, 1.5f, tileLayer))
|
||||
if (Physics.Raycast(transform.position, Vector3.down, out var hit, 2f, tileLayer))
|
||||
{
|
||||
if (hit.collider.TryGetComponent<TileViewAdapter>(out var tile))
|
||||
{
|
||||
@@ -44,15 +49,25 @@ namespace Infrastructure.Unity
|
||||
|
||||
private bool IsGrounded()
|
||||
{
|
||||
return Physics.Raycast(transform.position, Vector3.down, out var hit, 1.15f, tileLayer);
|
||||
return Physics.Raycast(transform.position, Vector3.down, out var hit, 2f, tileLayer);
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (_target)
|
||||
if (!_target) return;
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(transform.position, _target.transform.position);
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision other)
|
||||
{
|
||||
if (!_target) return;
|
||||
|
||||
if (other.gameObject == _target.gameObject)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(transform.position, _target.transform.position);
|
||||
_onCaughtCallback?.Invoke();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user