- Home /
simple movement 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
Edit : 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.
Answer by FLASHDENMARK · Apr 15, 2011 at 11:50 AM
You want the character to turn in a instant? then mabye this is for you:
var speed : float; var rotateSpeed = 10.0;
function Update () { transform.Translate(Input.GetAxis("Horizontal") Vector3.right speed * Time.deltaTime);
transform.Translate(Input.GetAxis("Vertical") Vector3.forward speed * Time.deltaTime);
if(Input.GetKey("j")) { transform.localEulerAngles.y += rotateSpeed; } if(transform.localEulerAngles.y >= 181) { transform.localEulerAngles.y = 180; }
if(Input.GetKey("l")) { transform.localEulerAngles.y -= rotateSpeed; } if(transform.localEulerAngles.y <= 0) { transform.localEulerAngles.y = 1; } }
Simple, but I believe that this is what you want. If not please tell me so I mabye further can help you.
Edit: The character will turn with the J and L key. You can of course change that. :)
Edit2: The characters angles can be different form mine to yours so where it says:
if(transform.localEulerAngles.y >= 181)
and
if(transform.localEulerAngles.y <= 0)
you may need to change those if your restricted movement dose not match.
can u implement my script in it ? or i would have to write it again ? thanx for ur help
The it is done. I hope this is what you are looking for. (Your script is now implemented with $$anonymous$$e).
Happy to help :)
OrangeLightning, would you please hint on how to make this movement smooth but won't go higher than 90 deg? thanks,
Your answer
Follow this Question
Related Questions
How can I rotate my player to look at the direction my Joystick is pointing to? (Top-Down 2D) 3 Answers
Add Force To One Object in Relation to the Rotation of Another Object (C#) 1 Answer
Can't get gravity to work proberly (transform) 2 Answers
Updating rotation of client not working - strange error 0 Answers