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;
Instantiate(SpinningRange, transform.position, Quaternion.LookRotation(contact.normal) );
i hope someone can help me =)
Answer by Bunny83
Jun 10, 2011 at 12:25 PM
I guess the problem is that you don't set the up-vector explicitly.
Therefore you call Quaternion.LookRotation like this:
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.
Answer by Anxo
Jun 10, 2011 at 11:47 AM
if you just want it to look up, I think you can use.
Instatiate(SpinningRange, transform.position, Quaternion.SetLookRotation(Vector3.up));
var Clone : GameObject = Instatiate(SpinningRange, transform.position,transform.rotation);
Clone.rotation = (desired rotation);
SetLookRotation is not a static member function. It can only be used on instances of Quaternions
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
3 People are following this question.
LookRotation Between 2 Points
Problem snapping object to different normals, but maintaining x axis orientation
Orient a vehicle to the ground and in the direction of its travel.
"Look rotation viewing vector is zero" error
Misbehavior with Quaternion.Slerp