- Home /
How to know if a gameobject is rotating?
Hello,
I have a GameObject
(a cube), and I make it rotate on X or Y axis.
I use a Quaternion.Lerp
to "animate" its moves. However I'd like to wait before it has finished its rotation before asking him to rotate another time. That's why I'd like to know how to be sure to quaternion are equals.
First I tried with the Quaternion's ==
operator (as mentionned in the documentation):
if ( final_rotation == transform.rotation )
But sometimes it returned me false even after the Lerp has finished for a long time. So I tried testing the Vector3
values:
if ( final_rotation.eulerAngles == transform.rotation.eulerAngles )
And it sometimes give me the same result : it returns me false even if Debug.Log returns me the same result.
I think it's something in relation to float
precision, but I can't find how to deal with it. Thank you in advance.
Why are you doing all this?
Don't forget unity IS A GA$$anonymous$$E ENGINE .. it has full physics built in. You do not need to do any of this. Good news!
Just add some force (torque in this case) and PhysX does everything.
Answer by whydoidoit · Jun 23, 2012 at 11:16 AM
The problem with Slerp is it can take a really long time to finish, especially using a Time.deltaTime calculation. You are probably better off checking for a small difference in the angles:
if((final_rotation.eulerAngles - transform.rotation.eulerAngles).sqrMagnitude < 0.1) {
...
}
For the second time of the day: thank you. I have to read those maths books.
The only one to read if you ask me is $$anonymous$$athematics for 3D Game Program$$anonymous$$g and Computer Graphics - my math bible :) In truth I'm pretty hopeless at $$anonymous$$ath (at least mathematical notation) but the stuff you need isn't so bad, I get most of it by playing around and Google...
This is exactly what I've began to read few days ago. That's reassuring :)
hey, what about
Real-Time Rendering $$anonymous$$as Akenine-$$anonymous$$oller
Real-Time Collision Detection Christer Ericson
The (New) Turing Omnibus: 66 Excursions in Computer Science DEWDNEY
sed:
$$anonymous$$athematics for 3D Game Program$$anonymous$$g and Computer Graphics John Flynt, Eric Lengyel
I also strongly recommend
Les Demoiselles de Rochefort. Catherine Deneuve, et al