- Home /
Animation works, pathfinding works, but they don't work together.
I'm working on an RTS. I have a prefab basic unit I'm using as the framework for all my units. I'm using A* Pathfinding Pro, a very nifty pathfinding solution, and my unit can successfully navigate his way around my map, avoiding obstacles and the like.
My main issue comes from being able to work an Animator Controller - I've got it loaded with some animations like Idle, Walk, Run, etc, and when the game starts up the unit automatically enters the Idle state. However, I can't seem to a) loop animations appropriately (after Idle has played through it advances to my Run animation for a moment, then back to Idle), and b) the only way I've found to make the unit actually follow the path it generates in the pathfinder totally bypasses the animation, so he just remains in the Idle state while he floats towards the target position.
Here's my animator controller:
Ultimately, I need my unit to remain in whatever state I put it in until I say otherwise, and I need to be able to use the movement animations to progress along the calculated path. If any other images or descriptions would help, I'm happy to oblige. Thanks for any help!
Are you making sure you're updating the animator parameters (e.g. speed) based on what A* is doing?
I tried doing what they show in the script tutorial:
http://unity3d.com/learn/tutorials/modules/beginner/animation/animator-scripting
Whenever I attempt using the StringToHash function, I get a message saying Hash #(some int value) doesn't exist as a parameter. So basically, I haven't worked out how that process is supposed to be done. Is that how the animation and A* relate?
Answer by Bodkin · Jun 13, 2014 at 07:22 PM
For the transitions to other animations you have to set a parameter such as speed. Then use that to trigger your animation. For example the transition from idle to walk would be "Speed > 0" this can be set up when you press a transition arrow on the animator. The code ,however, would have to look like this:
if (Input.GetKeyDown("space")){
gameObject.GetComponent<Animator>().SetFloat("Speed",1);
}
else{
gameObject.GetComponent<Animator>().SetFloat("Speed",0);
}
Make sure to set the parameters.
For more information: http://www.youtube.com/watch?v=Xx21y9eJq1U
Your answer
Follow this Question
Related Questions
A* Pathfinding with mecanim and rotation 1 Answer
How to Change the Motion of an Animation State in an Animator Controller at Run-Time? 1 Answer
Animation state not transitioning at 100% 1 Answer
How to play character animation when using A* pathfinding 0 Answers
Why does this animator appear to occupy two states, but report only one? 0 Answers