Add random point moving.
This commit is contained in:
@ -1,37 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.MLAgents;
|
||||
using Unity.MLAgents.Sensors;
|
||||
using Unity.MLAgents.Actuators;
|
||||
|
||||
[RequireComponent(typeof(MovementController))]
|
||||
public class NPC : Agent
|
||||
{
|
||||
public float LastTimeHit;
|
||||
private BaseBehaviour NPCBehaviour;
|
||||
public List<Action> ActionList;
|
||||
|
||||
[SerializeField]
|
||||
private List<ISensor> SensorList; // todo тут интерфейс должен быть наш
|
||||
|
||||
public void SetBehaviour(BaseBehaviour behaviour) => NPCBehaviour = behaviour;
|
||||
public Team Team { get; set; }
|
||||
|
||||
[HideInInspector]
|
||||
private float LastTimeHit;
|
||||
public CharacterCondition Condition;
|
||||
|
||||
public MovementController moveController;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
Condition = new CharacterCondition();
|
||||
moveController = gameObject.GetComponent<MovementController>();
|
||||
}
|
||||
|
||||
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
// Target and Agent positions
|
||||
foreach (var _sensor in SensorList)
|
||||
sensor.AddObservation(Condition.HealthPoints);
|
||||
sensor.AddObservation(Condition.ArmourPoints);
|
||||
sensor.AddObservation(Condition.Ammunition);
|
||||
sensor.AddObservation((int)Condition.npcState);
|
||||
}
|
||||
|
||||
public override void Heuristic(in ActionBuffers actionsOut)
|
||||
{
|
||||
var discreteActionsOut = actionsOut.DiscreteActions;
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
sensor.AddObservation(1); // todo
|
||||
// sensor.AddObservation(_sensor.GetValue());
|
||||
discreteActionsOut[0] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
//NPCBehaviour.DoAction();
|
||||
if (actions.DiscreteActions[0] == 1)
|
||||
moveController.MoveToRandomPoint();
|
||||
}
|
||||
|
||||
public event Action<object> OnKilledEvent;
|
||||
public void GetDamage(float damage)
|
||||
{
|
||||
Condition.GiveHealth(-Mathf.RoundToInt(damage * (1 - Condition.ArmourPoints * 0.5f)));
|
||||
Condition.GiveArmour(-Mathf.RoundToInt(Mathf.Sqrt(damage) * 5));
|
||||
|
||||
if (Condition.HealthPoints < 0)
|
||||
OnKilledEvent?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user