- Home /
Do tutorials. Read the Manual.
how to add a walking animation when character is moving?
Hi guy, im new to unity 3d and i have a problem . i have a zombie prefab and a walking animation.i want to add that animation when my zombie is moving.
Drag the prefab into scene. Add your animations, relevant animation component and script.
Drag the Hierarchy GameObject you created Back in to the project manager to create a new prefab with your newly set up character.
Answer by thornekey · Aug 03, 2014 at 06:52 AM
Hi, welcome to unity :)
You can make your player animate when moving like this:
public float stopAnimation = 0.5f;
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if ((directionVector.x > stopAnimation || directionVector.x < -stopAnimation) ||
(directionVector.y > stopAnimation || directionVector.y < - stopAnimation) ||
(directionVector.z > stopAnimation || directionVector.z < - stopAnimation)) {
animation.Blend("YourAnimationNameWalk");
} else {
animation.Blend("YourAnimationNameIdle");
}
I suggest you read up on what this actually means. Its quite simple, and basic to read. Good Luck.
Remember to check the reference page for quick tips and solutions.
Answer by Firedan1176 · Aug 03, 2014 at 07:42 AM
You can also use Unity's Mecanim to sort of visually "program" your animations and parameters to toggle between animations on a player. You can find more here.
Answer by $$anonymous$$ · Aug 03, 2014 at 11:25 AM
Whoa whoa whoa, misread I thought we were talking about the player... In any case you would use the Animator Component and Move Towards Component...