Initial. Added files
This commit is contained in:
38
Assets/Scripts/Character/MovementController.cs
Executable file
38
Assets/Scripts/Character/MovementController.cs
Executable file
@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user