- Home /
Help with Quaternion.FromToRotation
I am trying to use Quaternion.FromToRotation to point an object in a specified direction along a specified axis. If I have this code called every frame, it works, but every other frame, the rotation gets toggled 90 degrees, so I end up with a ton of ghosting.
Vector3 toOrig2 = Globals.steerOrigin - Globals.handles[i].transform.position;
Globals.handles[i].transform.rotation = Quaternion.FromToRotation(-Globals.handles[i].transform.forward, toOrig2);
After the 1st call, shouldn't the -Globals.handles[i].transform.forward and toOrig2 be the same and result in no change? I call this every frame because the object it is applied to may or may not be moved each frame. I'd rather not have to store if it's moved since the last frame and only update the rotation in that case.
Answer by homer_3 · Jun 30, 2016 at 01:51 AM
It looks like every other frame this will toggle to be 90 degrees off from what I want. So I put this check in after the 1st FromToRotation:
if(Vector3.Angle(toOrig2, -Globals.handles[i].transform.forward) > 10)
{
Globals.handles[i].transform.rotation = Quaternion.FromToRotation(-Globals.handles[i].transform.forward, toOrig2);
}
in an attempt to undo the unwanted rotations. This still doesn't seem to work to well to fix the issue though.
Your answer
Follow this Question
Related Questions
How to make character rotate in the direction of movement and direction of the camera? 1 Answer
Quaternion.Slerp() behaves weirdly when turning to look at moving object 2 Answers
Rotating an object in relation to its endpoints 1 Answer
Boxcast Rotaion/ Orientation Help 1 Answer
How can I instantiate a gameobject facing another gameobject 2D? 0 Answers