- Home /
Running Chicken Controls
![alt text][1]My group and I are developing a game for a class project and we would like to know how to control the chicken. We want the chicken to run using the left + right arrow key, if I press left arrow key, the left foot moves forward. And if I press the right arrow key, the right foot moves forward, so that the chicken can run by pressing the left + right arrow keys alternately.
our game is going to be a 3D chicken racing game [1]: /storage/temp/6098-chic.png
You'd have to explain your project, and include an image. For example, is it 2d, 3d, do you use CharacterControllers, or what?
Answer by MaGuSware™ · Dec 27, 2012 at 06:55 AM
Out of your update loop declare a new int variable.
C# - int lastStep = 0; //0 = no step, 1 = left step, 2 = right step
JS - private var lastStep : int = 0;
And in the update:
if(Input.GetKeyDown(KeyCode.LeftArrow) && lastStep != 1)
{
DoLeftStep();
lastStep = 1;
}
else if (Input.GetKeyDown(KeyCode.RightArrow) && lastStep != 2)
{
DoRightStep();
lastStep = 2;
}
This will give you the alternative pressing. You will just need to make the functions to step.
@bub - if that's the answer you want pls press the TIC$$anonymous$$ button, to close the question.
You get points for doing so, also. And only you can do it to keep the board tidy
Your answer
![](https://koobas.hobune.stream/wayback/20220613085938im_/https://answers.unity.com/themes/thub/images/avi.jpg)