39 lines
1.3 KiB
C#
Executable File
39 lines
1.3 KiB
C#
Executable File
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
[RequireComponent(typeof(NavMeshAgent))]
|
|
public class MovementController : MonoBehaviour
|
|
{
|
|
public NavPoint currentPosition { get; private set; }
|
|
[SerializeField] private MapManager mapManager;
|
|
[SerializeField] private NavMeshAgent navMeshAgent;
|
|
|
|
private void Start()
|
|
{
|
|
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
|
|
}
|
|
|
|
public void Move()
|
|
{
|
|
var pointCandidate = getPointCandidate();
|
|
goToNextNavPoint(pointCandidate);
|
|
}
|
|
|
|
|
|
// todo внутри сенсора передавать в mlagents как variable length observations: https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Learning-Environment-Design-Agents.md#variable-length-observations
|
|
private NavPoint getPointCandidate()
|
|
{
|
|
var NavPointsPositions = mapManager.navPoints
|
|
.Select(point => point.transform.position)
|
|
.Where(point => (currentPosition.transform.position - point).magnitude <= SettingsReader.Instance.GetSettings.movementSpeed)
|
|
.ToList();
|
|
//TODO AI
|
|
return null;
|
|
}
|
|
|
|
private void goToNextNavPoint(NavPoint destination) =>
|
|
navMeshAgent.SetDestination(destination.transform.position);
|
|
}
|