- Home /
Auto walk
Hi. I want to make an android game on unity with a character who walks automatically run and when I press right to go to the right and when I press left to go to the left. I tried to modify character controller (fps) but i failed.
That's great. Do you have a question that we can answer for you?
Answer by Khrome83 · Feb 03, 2012 at 03:03 AM
Can you post any code for how you are handling the character?
It sounds like what you want to do, is play a looping walk animation, while making the character continue to translate in a direction.
I don't know the android inputs, but it would be something like this -
var speed:float;
function Update() {
// Test for Left Input - Else Assume Right
if(left){
transform.rotation(0,180,0);
animation.Play("walk");
transform.Translate((Vector3.forward * speed) * Time.deltaTime);
} else {
transform.rotation(0,0,0);
animation.Play("walk");
transform.Translate((Vector3.forward * speed) * Time.deltaTime);
}
}
All of this is assume this is in the script attached to the object, the player. As well as the Y axis being vertices, rotating 180 if not facing that way currently. I haven't tested this, there might need to be some additional checks, like if the character is already rotated, or if the animation is currently playing. This also assumes that Vector3.forward will give you the direction the model is facing, assuming it was imported right and the prefab was created right. If it was imported wrong, you can rotate the object inside the prefab after making it a child of a empty game object. The Time.deltaTime will make sure it translates forwards at a constant speed regardless of frame rate. Everything is inside of the Update function so that it runs every frame to keep the character moving. You will need to add conditionals to break out of this action if the character - jumps, stops or any other action.
Everything above is in JavaScript
Without code posted, it is hard to answer these questions. Good Luck.
Answer by jhakestylez · Oct 05, 2014 at 09:38 AM
what he's trying to explain is the animation similar with the running game genre such as temple run, subway surfer. etc
Your answer
Follow this Question
Related Questions
Using Accelerometer to move and rotate a 3d cube from left to right 0 Answers
How to turn your object left and right 1 Answer
Rigidbody2d Moving up and Down but not left and right 1 Answer
Skybox - Left and Right is swapped, needs fixing. 1 Answer
Pay animation if joystick pushed to left and another if joystick is pushed to right 2 Answers