Hi All
I’ve managed to get my character to move to a Raycast hit point smoothly at a consistent speed using Vector3.MoveTowards, with the ‘walk’ animation playing once (then returning to ‘idle’ animation).
I want to step it up a notch and get the ‘walk’ animation to loop while the character is moving to the hit point, then return to ‘idle’ when it has reached the hit point. Basically, so it doesn’t walk half way and slide the rest of the way.
Is there any way of achieving this? Here’s a snippet of my current code:
function Update ()
{
if(Input.GetMouseButtonDown(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit))
{
if(hit.transform.name == "NavBar")
{
Zombie.transform.rotation = Quaternion.LookRotation(transform.position - hit.point);
pointToGo = hit.point;
ZombieAnim.animation.CrossFade("Walk Legacy", 0.5);
ZombieIdle.animation.CrossFadeQueued("Idle Legacy", 0.4, QueueMode.CompleteOthers);
}
}
}
Zombie.transform.position = Vector3.MoveTowards(Zombie.transform.position, pointToGo, Time.deltaTime * speed);