- Home /
how to check if the object looks right or left?
i have a playercharachter which i want to play a different animation if it looks right or left, i have looked for code how to do this but i havent found anything that really helps does anyone knows? i'm using javascript
Answer by Mr.Z · Jan 07, 2013 at 10:28 PM
If what you want is to play different animations depending on where the player wants to move his character you can do it like this:
if (Input.GetKeyDown ("yourkey")) {
object.animation.Play( "animationName" );
}
no i'm looking for the code that checks if the object has no movement
Hmm...if you want to know when an object isn't moving, first we need to know what causes it to move. Do you press a key to move left and right? Does it move by itself unless some other variable is present?
that was what i was asking my question says "how to check if the object looks right or left?"
Ooooh, now I think I get what you mean. You want to know if you're standing still, but the mouse is moved in one direction or the other? So the input you're using is the mouse axis, rather than a button.
You'll probably want to use some variation of if(Input.GetAxis("horizontal")){action}. You can check out the details on this call at http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html, but the basics are that it provides you a number between -1 and 1 based on what you're doing with your mouse, and those numbers correspond to right and left.
If you're not sure what your horizontal axis is called, check out the input settings Edit > Project Settings > Input.
Your answer

Follow this Question
Related Questions
Moving an object to an x postion 1 Answer
Camera rotation around player while following. 6 Answers
x, y position to 360 degree 0 Answers
How to instantiate in self position. 1 Answer
Finding locations of Vertices on a Mesh 3 Answers