Final commit
This commit is contained in:
@ -23,10 +23,12 @@ public class MovementController : MonoBehaviour
|
||||
public Vector3 Velocity => navMeshAgent.velocity;
|
||||
private Dictionary<int, NavPoint> _idNavPointDict;
|
||||
private NPC _myNpc;
|
||||
private Settings _settings;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||
_settings = SettingsReader.Instance.GetSettings;
|
||||
navMeshAgent.speed = _settings.MovementSpeed;
|
||||
_idNavPointDict = MapManager.Instance.IDToNavPoint;
|
||||
_myNpc = GetComponent<NPC>();
|
||||
_firePointTransform = transform.GetChild(0);
|
||||
@ -42,15 +44,23 @@ public class MovementController : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
print($"{_myNpc.NpcState.ToString()}, {_myNpc.GetCharacter.Team}");
|
||||
if (Velocity.magnitude > 0)
|
||||
_myNpc.ChangeBaseState(NpcEnumState.InRunning);
|
||||
else
|
||||
if (ReachedDestination())
|
||||
{
|
||||
_myNpc.ChangeBaseState(_idNavPointDict[PointStartID].navType == NavPointType.Cover
|
||||
_myNpc.ChangePointState(_idNavPointDict[PointStartID].navType == NavPointType.Cover
|
||||
? NpcEnumState.InCover
|
||||
: NpcEnumState.InDirectPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
_myNpc.ChangeBodyState(NpcBodyState.Standing);
|
||||
_myNpc.ChangePointState(NpcEnumState.InRunning);
|
||||
}
|
||||
|
||||
if (_myNpc.NpcBodyState.State == NpcBodyState.Crouching)
|
||||
navMeshAgent.speed = _settings.MovementSpeed / 2;
|
||||
else
|
||||
navMeshAgent.speed = _settings.MovementSpeed;
|
||||
|
||||
}
|
||||
|
||||
private void UpdateFlagPosition()
|
||||
@ -68,7 +78,7 @@ public class MovementController : MonoBehaviour
|
||||
{
|
||||
return MapManager.Instance.NavPoints
|
||||
.Where(point =>
|
||||
(transform.position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
(transform.position - point.Position).magnitude < _settings.MovementDistance)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -93,11 +103,13 @@ public class MovementController : MonoBehaviour
|
||||
navMeshAgent.isStopped = true;
|
||||
}
|
||||
|
||||
public void ReachedDestination()
|
||||
public bool ReachedDestination()
|
||||
{
|
||||
if (navMeshAgent.remainingDistance < float.Epsilon)
|
||||
if (navMeshAgent.remainingDistance < 0.1f)
|
||||
{
|
||||
PointStartID = PointEndID;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public bool IsFiring => _assistant.fireAnimation;
|
||||
|
||||
public void ChangeBaseState(NpcEnumState state)
|
||||
public void ChangePointState(NpcEnumState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
@ -51,6 +51,19 @@ public class NPC : Agent, ICharacter
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeBodyState(NpcBodyState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case global::NpcBodyState.Crouching:
|
||||
NpcBodyState = _crouchingState;
|
||||
break;
|
||||
case global::NpcBodyState.Standing:
|
||||
NpcBodyState = _standingState;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region UnityEvents and ML
|
||||
private void Awake()
|
||||
@ -96,7 +109,6 @@ public class NPC : Agent, ICharacter
|
||||
if (_navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
|
||||
NpcState = _directState;
|
||||
_flagZone = GameObject.FindObjectOfType<FlagZone>();
|
||||
}
|
||||
|
||||
@ -143,35 +155,41 @@ public class NPC : Agent, ICharacter
|
||||
} ;
|
||||
}
|
||||
|
||||
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
|
||||
{
|
||||
if (!NpcState.InCover)
|
||||
actionMask.SetActionEnabled(0,0,false);
|
||||
if (!NpcState.InDirectPoint)
|
||||
actionMask.SetActionEnabled(0,1,false);
|
||||
if (!NpcState.IsRunning)
|
||||
actionMask.SetActionEnabled(0,2,false);
|
||||
base.WriteDiscreteActionMask(actionMask);
|
||||
}
|
||||
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
var result = actions.DiscreteActions;
|
||||
if (result[0] == 0)
|
||||
{
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Cover)
|
||||
return;
|
||||
NpcState = _coverState;
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: Peek(); break;
|
||||
case 1: Cover(); break;
|
||||
case 2: Peek(); _moveController.GoToNextNavPoint(_navPointIdDict[result[2]]); break;
|
||||
case 2: Peek();
|
||||
_moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);
|
||||
break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
}
|
||||
}
|
||||
if (result[0] == 1)
|
||||
{
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Direction)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: _moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);
|
||||
NpcState = _runningState; break;
|
||||
case 1: NpcState = _directState; break;
|
||||
case 0:
|
||||
_moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);break;
|
||||
case 1: break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
@ -179,13 +197,11 @@ public class NPC : Agent, ICharacter
|
||||
}
|
||||
|
||||
if (result[0] == 2)
|
||||
{
|
||||
if (_moveController.PointStartID == _moveController.PointEndID && _moveController.PointEndID != -1)
|
||||
return;
|
||||
{
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: _moveController.StopOnPath(); NpcState = _directState; break;
|
||||
case 1: _moveController.ReturnToStartPoint(); NpcState = _runningState; break;
|
||||
case 0: _moveController.StopOnPath(); break;
|
||||
case 1: _moveController.ReturnToStartPoint(); break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
|
Reference in New Issue
Block a user