# simple plan obect rotation

i am new to unity and programing … all i want to do is create a simple plane object and rotate it by use of the arrow keys… ie… up down left right… and example and explanations as to the hows and whys would be appreciated… i figure it would be something like … if key pressed up transform/rotate object on what ever axis or something …thanks in advance…

I need to say that is pretty difficult people answer your question and give you a done code. The best way to get some help here is to try to do your own code and post here if you’re with some kind of problem with it.

To do this you will basically need to take a look at Input.GetButton or Input.GetKey(to get the event of the key pressed) and transform.Rotate (to apply the rotation to the object in whatever axis you define). Check them in Unity API.

User input, rotating and moving objects are very straight forward.

``````private var speed : int = 100;
function Update () {
if (Input.GetKey (KeyCode.UpArrow)) transform.Rotate(Vector3.right*speed*Time.deltaTime);
if (Input.GetKey (KeyCode.DownArrow)) transform.Rotate(Vector3.left*speed*Time.deltaTime);
if (Input.GetKey (KeyCode.LeftArrow)) transform.Rotate(Vector3.up*speed*Time.deltaTime);
if (Input.GetKey (KeyCode.Rightward)) transform.Rotate(Vector3.down*speed*Time.deltaTime);
}
``````

Use the Input- and Transform-class. Use Time.deltaTime to make it frame independent.

Create a new Javascript by right-clicking in the Project folder. Open it and paste the code above, then drag the script-file from the Project folder to your object, either in the Hierarchy view or the Scene view.

Thanks that helps out some i think i understand a lil better…
so Input.Getkey (KeyCode.whatever key) assigns the key…
so i was right to assume it is a transform event
transform.rotate but what exactly is the vector3?
can speed be set within the transform.rotate(vector3.down*"speed replaced with a set speed or is this variable dependent?,