x


Input Help!

Im new at Unity and ive created a side on 2d game where a car goes at a constant speed (normally) and the user controls the rotation on the Z axis - ie tilt the car as it goes over ramps etc. Ive used the following script but im obviously going wrong as im not sure how to make the control make the car rotate, any edits to the script from the pros would be much appreciated!

function Update () { if(Input.GetAxis("Horizontal")){ Transform.Rotate(Vector3(0,0,1)); } }

more ▼

asked Jan 26 '12 at 10:53 PM

jmh gravatar image

jmh
-4 6 7 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

That function is modifying the math behind the Transform. The problem is that you're calling it directly from the class, not from an instance of the class. So you need the Transform component of your object, and you Unity being a good guy you can do that easily :

function Update(){
 if( Input.GetAxis("Horizontal") ){
  transform.Rotate(Vector3(0,0,1));
 } 
}

Not that different isn't it ? the important part is transform instead of Transform. If the object still don't rotate correctly, check your axis, or change the z on the rotation.

more ▼

answered Jan 27 '12 at 12:53 AM

Berenger gravatar image

Berenger
11.2k 12 19 54

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x982
x747
x230

asked: Jan 26 '12 at 10:53 PM

Seen: 442 times

Last Updated: Jan 27 '12 at 12:53 AM