Comments and answers for "Eulers from normal into rotation sometimes wrong."
http://answers.unity.com/questions/247041/eulers-from-normal-into-rotation-sometimes-wrong.html
The latest comments and answers for the question "Eulers from normal into rotation sometimes wrong."Answer by Wisearn
http://answers.unity.com/answers/248343/view.html
Thanks @Bunny83 and @syclamoth
It hadnt occured to me that the pivot point was the issue considering my test shape was symmetric but it makes sense now because the pivot point of the model is actually in the center >bottom< of the model (I just had "center" on in the view without realizing it) which explains why it started becoming less and less accurate.
Using temporary parenting with an empty gameobject solved my issue entierly.Fri, 04 May 2012 16:23:12 GMTWisearnAnswer by aldonaletto
http://answers.unity.com/answers/247465/view.html
Opposite to what it may seem (this fooled me at first too), using Rotate is correct: the room is already at some rotation when the collision occurs, thus it should be rotated from that orientation to the new one. The problem is the precision loss in quaternion-euler conversions - and there are two of them each collision. It would be better to just multiply the from-to rotation by the current rotation:
<pre>
function OnCollisionEnter(collisionInfo : Collision) {
newRotation = Quaternion.FromToRotation(collisionInfo.contacts[0].normal, Vector3.up);
Map.transform.rotation *= newRotation;
}
</pre>
But even this approach may accumulate errors, and rotate to weird positions after several collisions. To avoid this, you may try to force the eulerAngles to allowed angles after each rotation.<br>
According to the sapient Wikipedia, this is a rhombi-whatever solid:
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Leonardo_polyhedra.png/220px-Leonardo_polyhedra.png">
From this image (borrowed from wikipedia and Leonardo da Vinci), I suppose the eulerAngles xyz must all be integral multiples of 45 degrees. If this is true, you could try this:
<pre>
function OnCollisionEnter(collisionInfo : Collision) {
var newRot = Quaternion.FromToRotation(collisionInfo.contacts[0].normal, Vector3.up);
newRot = newRot * Map.transform.rotation; // find the new rotation
var euler = newRot.eulerAngles; // get the corresponding euler angles...
euler.x = Mathf.Round(euler.x / 45) * 45; // force them to be multiples of 45
euler.y = Mathf.Round(euler.y / 45) * 45;
euler.z = Mathf.Round(euler.z / 45) * 45;
Map.transform.eulerAngles = euler; // then assign the new absolute rotation
}
</pre>
By the way, this angle fixing could be applied to your approach as well (use Rotate, then fix the eulerAngles).<br>
The room will rotate around its own pivot, as @Bunny83 said, but this may be a desired behaviour in your case. If not, @syclamoth's suggestion is good: place an empty object at the hit point, child the room to it, apply the new rotation to the empty object and assign null to the room's parent.Wed, 02 May 2012 13:55:19 GMTaldonalettoComment by syclamoth on syclamoth's answer
http://answers.unity.com/comments/247432/view.html
Just use temporary parenting, should do the trick.Wed, 02 May 2012 12:44:36 GMTsyclamothComment by syclamoth
http://answers.unity.com/comments/247431/view.html
The whole deal with that line you quoted out of the Quaternion class is that you *can't* get a specific set of euler angles out of a given quaternion- the whole point of quaternions is that they can accurately describe a rotation, in a way that euler angles alone cannot. Hence, you are losing information when you convert a quaternion to a euler angle representation (similar to converting a double to a float).Wed, 02 May 2012 12:43:55 GMTsyclamothComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/247422/view.html
You're absolutely right, however if you set the rotation fix to the one you calculates you can't rotate your player anymore ;) But the incremental note is correct.
Sorry, just realized he rotates the $$anonymous$$ap and not the player ^^. Then you're right, however i don't think this would work since the map rotation happens around the maps origin and not around the contact point.Wed, 02 May 2012 12:31:43 GMTBunny83Answer by Paulius-Liekis
http://answers.unity.com/answers/247417/view.html
Wait, Transform.Rotate is incremental rotation, don't you want to set the rotation instead (transform.localEulerAngles = myQuaternonLook.eulerAngles)?
You don't need conversion to euler angles, you can simply assign quaternions: transform.localRotation = myQuaternonLook;
Having said that I have no opinion about this math in general :) Assuming that ContactPoint.normal is in world space - it makes sense.Wed, 02 May 2012 12:15:46 GMTPaulius-LiekisComment by Wisearn
http://answers.unity.com/comments/247323/view.html
I changed it to "$$anonymous$$ap.transform.Rotate(myQuaternonLook.eulerAngles);" and I get the exact same behaviour.
Apparently taking eulerAngles from my FromToRotation Quaternion isnt what I'm looking for "when you convert a quaternion to euler angles, the quaternion gives you no gurantuee out of which euler angle you will get out".
$$anonymous$$aybe I just need to convert my direction to eulerangles manually? Any math-wizards around? The normal should have all I need as compared to Vector3.up...Wed, 02 May 2012 08:44:59 GMTWisearnComment by syclamoth
http://answers.unity.com/comments/247203/view.html
Yeah, I'm pretty sure that page *specifically states* that what you're trying to do here won't work.Wed, 02 May 2012 02:34:10 GMTsyclamothComment by rutter
http://answers.unity.com/comments/247200/view.html
Not sure if this is your problem, but you might check the caveat here about setting angles over 360: http://unity3d.com/support/documentation/ScriptReference/Transform-eulerAngles.htmlWed, 02 May 2012 02:32:22 GMTrutter