You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class PlayerMovement : MonoBehaviour
|
|
{
|
|
[Header("Components")]
|
|
[SerializeField] private NavMeshAgent agent;
|
|
[SerializeField] private Animator animator;
|
|
|
|
|
|
private float lookRotationSpeed = 8f;
|
|
|
|
void Awake()
|
|
{
|
|
agent = GetComponent<NavMeshAgent>();
|
|
animator = GetComponent<Animator>();
|
|
|
|
//input = new CustomActions();
|
|
//AssignInputs();
|
|
}
|
|
|
|
public void MoveTo(Vector3 point, Action action = null)
|
|
{
|
|
agent.destination = point;
|
|
|
|
//replace later
|
|
action?.Invoke();
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (!agent.pathPending && agent.remainingDistance > agent.stoppingDistance)
|
|
{
|
|
FaceTarget();
|
|
}
|
|
////SetAnimations();
|
|
}
|
|
|
|
private void FaceTarget()
|
|
{
|
|
if (agent.velocity == Vector3.zero) return;
|
|
|
|
Vector3 direction = (agent.destination - transform.position).normalized;
|
|
Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, 0, direction.z));
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * lookRotationSpeed);
|
|
}
|
|
|
|
public void StopMovement()
|
|
{
|
|
agent.destination = transform.position;
|
|
}
|
|
|
|
//void SetAnimations()
|
|
//{
|
|
// if (agent.velocity == Vector3.zero)
|
|
// { animator.Play(IDLE); }
|
|
// else
|
|
// { animator.Play(WALK); }
|
|
//}
|
|
}
|