- Home /
simple movement and rotate help!
hello i am trying to make a 2D platform , but i am a 3D artist so i am using 3D models with orthographic camera. I have wrote a script for moving my character left,right at X axis and up,down at Y axis. Similar to anyother side-scroller with difference that the character is flying so it can move up,down freely. Here is my script.
var speed : float; function Update () {
transform.Translate(Input.GetAxis("Horizontal") Vector3.right speed * Time.deltaTime);
transform.Translate(Input.GetAxis("Vertical") Vector3.forward speed * Time.deltaTime);
} what i want is to character rotate to -90 degrees when i press right button and when i again press left it is to rotate 90 degrees to show a kind of movement. Please help ,
Thanx in Advance
Anonymous
Again : what i wanted is when i press right it should turn -90 and then should move on the right side and when then i press left it should again rotate to 90 and move in the direction.
I think you mean turn 180 lol turning 90 degrees would make him face the background or the camera.
Answer by Joshua · Apr 16, 2011 at 01:48 PM
Put the variable at the top of your function, put the if statement in your update function. This is just of the top of my mind and untested code, so I hope it works.
var facingRight : boolean = true
if (Input.GetAxis("Horizontal") > 0 && !facingRight )
transform.eulerAngels.x = 0;
if (Input.GetAxis("Horizontal") < 0 && facingRight )
transform.eulerAngels.x = 180;
it don't work please tell elaborate , i am a noob in scripting :(
Your answer
Follow this Question
Related Questions
Moving character relative to camera position. 1 Answer
Sidescroller, rotating via mouse control 0 Answers
Quaternion and rotation of object 1 Answer
Cant align players up vector to surface normal 0 Answers
Curve player movement 1 Answer