Fixes? and side channels.

This commit is contained in:
2022-05-17 19:09:50 +07:00
parent b5aff44f79
commit e976a3fbff
18 changed files with 454 additions and 90 deletions

View File

@ -6,6 +6,7 @@ using UnityEngine.AI;
using Random = UnityEngine.Random;
[RequireComponent(typeof(NavMeshAgent))]
[RequireComponent(typeof(NPC))]
public class MovementController : MonoBehaviour
{
private Transform _firePointTransform;
@ -21,12 +22,13 @@ public class MovementController : MonoBehaviour
public float RemainingDistance => navMeshAgent.remainingDistance;
public Vector3 Velocity => navMeshAgent.velocity;
private Dictionary<int, NavPoint> _idNavPointDict;
private NPC _myNpc;
private void Awake()
{
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
_idNavPointDict = MapManager.Instance.IDToNavPoint;
_myNpc = GetComponent<NPC>();
_firePointTransform = transform.GetChild(0);
InvokeRepeating(nameof(UpdateFlagPosition), 0, UpdateFlagPositionDelay);
InvokeRepeating(nameof(ReachedDestination), 0, UpdateReachedDestinationDelay);
@ -38,11 +40,25 @@ public class MovementController : MonoBehaviour
CancelInvoke(nameof(ReachedDestination));
}
private void Update()
{
print($"{_myNpc.NpcState.ToString()}, {_myNpc.GetCharacter.Team}");
if (Velocity.magnitude > 0)
_myNpc.ChangeBaseState(NpcEnumState.InRunning);
else
{
_myNpc.ChangeBaseState(_idNavPointDict[PointStartID].navType == NavPointType.Cover
? NpcEnumState.InCover
: NpcEnumState.InDirectPoint);
}
}
private void UpdateFlagPosition()
{
FlagDistance = (flag.transform.position - gameObject.transform.position).magnitude;
}
[Obsolete]
public void MoveToRandomPoint()
{
GoToNextNavPoint(MapManager.Instance.NavPoints[Random.Range(0, MapManager.Instance.NavPoints.Count)]);
@ -79,7 +95,9 @@ public class MovementController : MonoBehaviour
public void ReachedDestination()
{
if ((navMeshAgent.isStopped == false) && (navMeshAgent.velocity.magnitude < 0.1))
if (navMeshAgent.remainingDistance < float.Epsilon)
{
PointStartID = PointEndID;
}
}
}