x


Quaternion.LookRotation

hey, I have a little problem with Quaternions.

i am shooting a little ball, and when that ball collides with the ground a flat sphere( circle ) should appear. Everything works just fine, but the rotation is wrong. I am using the LookRotation-function of the Quaternion, but it seems i don't fully understand what it does. (for example my level is a completely flat, so it should look exactly 90° upwards. But the rotation of the circle is x 76, y 74, z 1)

ATM my code looks like that:

void OnCollisionEnter(Collision collision)
{
    contact = collision.contacts[0];

    Instantiate(SpinningRange, transform.position, Quaternion.LookRotation(contact.normal) );
}

i hope someone can help me =)

more ▼

asked Jun 10, 2011 at 11:23 AM

stony gravatar image

stony
3 6 4 5

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

2 answers: sort voted first

I guess the problem is that you don't set the up-vector explicitly.

Therefore you call Quaternion.LookRotation like this:

Quaternion.LookRotation(contact.normal,Vector3.up);

The problem is that if contact.normal equals Vector3.up you get in trouble. The second parameter (the up-vector) specifies the rotation around the axis given in the first parameter. If the first parameter is Vector3.up you have to use Vector3.right or .forward as up-vector.

more ▼

answered Jun 10, 2011 at 12:25 PM

Bunny83 gravatar image

Bunny83
75.2k 25 91 324

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

if you just want it to look up, I think you can use.

Instatiate(SpinningRange, transform.position, Quaternion.SetLookRotation(Vector3.up));

or

var Clone : GameObject = Instatiate(SpinningRange, transform.position,transform.rotation);
Clone.rotation = (desired rotation);
more ▼

answered Jun 10, 2011 at 11:47 AM

Anxo gravatar image

Anxo
2k 72 61 96

SetLookRotation is not a static member function. It can only be used on instances of Quaternions

Jun 10, 2011 at 12:21 PM Bunny83
(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:

x759
x164
x71

asked: Jun 10, 2011 at 11:23 AM

Seen: 4675 times

Last Updated: Jun 10, 2011 at 12:25 PM