- Home /
how alternate walk cycle javascript
Hi all, I'm very very new to coding (3D artist by trade), but am trying to create a simple walk cycle that is broken into 2 halves. I've baked the keys for this, imported to unity, split the animations in the inspector. I have: idle walk start animation - where character puts left leg forward right foot forward animation left foot forward animation stopping with right foot stopping with left foot
For now the character will only move in one direction, and all I'm trying to do at the moment is get the animations to play in the correct sequence. Here's the code I have so far: (using javascript)
function Update () { if (Input.GetKeyDown("left")) leftStart(); }
function leftStart ()
{
animation.PlayQueued("left start");
if (animation.IsPlaying("left start") && Input.GetKeyUp("left"))
rightStop();
else if (animation.IsPlaying("left start") && Input.GetKey("left"))
walk();
}
function walk ()
{
animation.PlayQueued("right forward");
animation.PlayQueued("left forward");
if (animation.IsPlaying("left forward") && Input.GetKeyUp("left"))
rightStop();
if (animation.IsPlaying("right forward") && Input.GetKeyUp("left"))
leftStop();
}
function leftStop ()
{
animation.PlayQueued("left stop");
}
function rightStop ()
{
animation.PlayQueued("right stop");
}
I've tried putting all of the if statements into the main function, having lots of functions, re-arranging everything, trying: if (animation["left forward"].enabled == true) instead of is.Playing, but each has a different and wrong behaviour. My suspicion is that something is going wrong with the GetKeyDown part, as if I repeatedly tap the left button it seems to work a bit better, but of course this isn't what I want. My other suspicion is that I ought to leave scripting well alone and stick to 3D artwork! But if someone can help me it would be much appreciated.
Save yourself the trouble, and look up the Unity Locomotion System. It's far more fully featured than anything you or I could write, and it's already been made. It's a free download, too!
Answer by enginehouse · Jul 16, 2012 at 01:35 PM
cool thanks. I'd come across this before but assumed it was only for procedural animation? Does it also work for pre-keyed?
Your answer
Follow this Question
Related Questions
Animation... Unity 3D...Blender...3rd Person 2 Answers
Animation Won't Start 3 Answers
How would you make a shapeshifting mechanic in a game? 1 Answer
John Lemon Popping While Walking 0 Answers