- Home /
Loop animation until character reaches hit.point
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);
Answer by hollym16 · Apr 11, 2014 at 02:37 PM
I found a great solution that someone else posted, found here:
http://answers.unity3d.com/questions/401548/when-character-stops-moving-stop-walk-animation.html
Your answer
Follow this Question
Related Questions
I need help with Jump animations 0 Answers
Door only opening once on Raycast 1 Answer
Switching between animations 1 Answer
Get GameObject to face and move towards Raycast hit point 1 Answer