- Home /
Question by
RubiixDev · Aug 14, 2020 at 10:31 AM ·
animationmovementclickclick to moveclicktomove
How do i make my chracter stop moving when the destination has been reached?,How do i prevent my character from moving when reached the destination
Im trying to do a Click to move character controller but my character doesnt stop when the destination has been reached, any ideas? Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;
public class MovimentTerceraPersona : MonoBehaviour
{
public NavMeshAgent playerAgent;
public Animator Animator;
public Camera Cam;
public Transform cam;
private Vector3 clickedPosition;
private Vector3 position;
private void Start()
{
}
private void Update()
{
if (Input.GetMouseButtonDown(0) )
{
GetInteraction();
Debug.Log(clickedPosition);
Animator.SetFloat("Running", 1.1f);
}
if (playerAgent.remainingDistance <= playerAgent.stoppingDistance)
{
Debug.Log("Arrived");
Animator.SetFloat("Running", 0.9f);
}
//Debug.Log(playerAgent.remainingDistance);
}
void GetInteraction()
{
RaycastHit hit;
Ray ray = Cam.ScreenPointToRay(Input.mousePosition);
clickedPosition = Input.mousePosition;
if (Physics.Raycast(ray, out hit, 1000))
{
playerAgent.destination = hit.point;
}
}
}
Comment