Fixes? and side channels.
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Animators.Leonid_Animator;
|
||||
using Animators.Leonid_Animator.Bot;
|
||||
using Unity.MLAgents;
|
||||
using Unity.MLAgents.Actuators;
|
||||
@ -15,9 +13,8 @@ using UnityEngine;
|
||||
public class NPC : Agent, ICharacter
|
||||
{
|
||||
private CharacterCondition _condition;
|
||||
private FlagZone _flagZone = null;
|
||||
|
||||
private INpcBaseState NpcState { get; set; }
|
||||
private FlagZone _flagZone;
|
||||
public INpcBaseState NpcState { get; set; }
|
||||
public INpcBaseBodyState NpcBodyState { get; private set; }
|
||||
|
||||
[field: HideInInspector]
|
||||
@ -38,6 +35,22 @@ public class NPC : Agent, ICharacter
|
||||
private Dictionary<int, NavPoint> _navPointIdDict;
|
||||
|
||||
public bool IsFiring => _assistant.fireAnimation;
|
||||
|
||||
public void ChangeBaseState(NpcEnumState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case NpcEnumState.InCover:
|
||||
NpcState = _coverState;
|
||||
break;
|
||||
case NpcEnumState.InRunning:
|
||||
NpcState = _runningState;
|
||||
break;
|
||||
case NpcEnumState.InDirectPoint:
|
||||
NpcState = _directState;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region UnityEvents and ML
|
||||
private void Awake()
|
||||
@ -89,7 +102,6 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
Debug.Log("Collect observations called!");
|
||||
_navPointIdDict = MapManager.Instance.IDToNavPoint;
|
||||
if (_navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
@ -109,8 +121,8 @@ public class NPC : Agent, ICharacter
|
||||
sensor.AddObservation((int)NpcState.State);
|
||||
sensor.AddObservation((int)NpcBodyState.State);
|
||||
sensor.AddObservation(GameManager.IsEnemyNearby(gameObject.transform.position, GetCharacter.Team));
|
||||
sensor.AddObservation(_navPointIdDict[_moveController.PointStartID].DeathAttr);
|
||||
sensor.AddObservation(_navPointIdDict[_moveController.PointEndID].DeathAttr);
|
||||
//sensor.AddObservation(_navPointIdDict[_moveController.PointStartID].DeathAttr);
|
||||
//sensor.AddObservation(_navPointIdDict[_moveController.PointEndID].DeathAttr);
|
||||
sensor.AddObservation(_moveController.FlagDistance);
|
||||
|
||||
//point sensors
|
||||
@ -134,7 +146,6 @@ public class NPC : Agent, ICharacter
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
var result = actions.DiscreteActions;
|
||||
print(result[0]);
|
||||
if (result[0] == 0)
|
||||
{
|
||||
if (_navPointIdDict[_moveController.PointStartID].navType != NavPointType.Cover)
|
||||
@ -159,7 +170,7 @@ public class NPC : Agent, ICharacter
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: _moveController.GoToNextNavPoint(_navPointIdDict[result[2]]);
|
||||
NpcState = _runningState; Debug.Log("Go to point " + result[2]);break;
|
||||
NpcState = _runningState; break;
|
||||
case 1: NpcState = _directState; break;
|
||||
case 2: break;
|
||||
case 3: break;
|
||||
@ -180,6 +191,7 @@ public class NPC : Agent, ICharacter
|
||||
default: throw new ArgumentException("Undefined Action received");
|
||||
}
|
||||
}
|
||||
AddReward(-0.001f);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -204,6 +216,7 @@ public class NPC : Agent, ICharacter
|
||||
_condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - _condition.ArmourPoints * 0.5f)));
|
||||
_condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
|
||||
OnDamageReceived?.Invoke(damage, GetCharacter.Team);
|
||||
AddReward(-0.03f);
|
||||
if (_condition.HealthPoints < 1)
|
||||
{
|
||||
Die();
|
||||
@ -212,6 +225,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
private void Die()
|
||||
{
|
||||
AddReward(-0.2f);
|
||||
OnDeathEvent?.Invoke(true);
|
||||
MapManager.AddDeathAttributeToPoints(_moveController.PointStartID, _moveController.PointEndID,
|
||||
_moveController.DistanceToGo, _moveController.RemainingDistance);
|
||||
|
@ -26,8 +26,8 @@ public class Player : MonoBehaviour, ICharacter
|
||||
PlayerCharacter.LastTimeHit = TimeManager.Instance.CurrentTime;
|
||||
Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
|
||||
Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
|
||||
|
||||
if (Condition.HealthPoints < 1)
|
||||
print(Condition.HealthPoints);
|
||||
if (Condition.HealthPoints < 10)
|
||||
Die();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user