x


How to change rotation through script

I want to know how to change an object's rotation on specific axis through script when it touches the ground because I am working on a flight sim. I know how to chage the rotation of it but I don't know how to change rotation for only the X and Z axis but keep the rotation of the Y axis the same. I use this code.

function OnCollisionEnter(collision : Collision){

if (collision.gameObject.name == "Terrain"){ transform.rotation = Quaternion.Euler(0,0,0); } }

more ▼

asked Jul 04 '12 at 01:44 AM

Legozing gravatar image

Legozing
1 1 1 1

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

2 answers: sort voted first
function OnCollisionEnter(collision : Collision){

if (collision.gameObject.name == "Terrain"){ transform.rotation = Quaternion.Euler(X,Y,Z); } }

Alternatively, if it is a rigidbody, you can lock certain rotations on the rigidbody settings of the object.

more ▼

answered Jul 04 '12 at 05:18 AM

xKroniK13x gravatar image

xKroniK13x
168 3 10 14

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

Use something like this:

  var rotationVector = transform.rotation.eulerAngles;
  rotationVector.z = 0;
  transform.rotation = Quaternion.Euler(rotationVector);
more ▼

answered Jul 04 '12 at 03:41 AM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 101

(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:

x3343
x2174
x380
x323
x98

asked: Jul 04 '12 at 01:44 AM

Seen: 1154 times

Last Updated: Jul 04 '12 at 05:18 AM