Rotate non-forward vector to face direction?
This feels like it should be obvious but I've been walking myself in circles for ages.
I have a cube that moves by flipping, and when I click, I want the face that is closest to the target point to rotate to look at it. I can get the facing direction of the closest face easily, the trouble is that every rotation option I find assumes it's rotating the forward vector to look in the direction. Here's what I'm currently using:
float step = speed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(facing_direction, target_direction, step, 0.0F);
cube.transform.rotation = Quaternion.LookRotation(newDir);
But LookRotation creates a rotation where the given vector is forward. Seeing as my forward could be facing any way, it's giving me the wrong result. I thought perhaps I just need to offset the rotation and tried adding:
Quaternion offset = Quaternion.FromToRotation(facing, cube.transform.forward);
cube.transform.rotation = Quaternion.LookRotation(newDir) * offset;
But it's still freaking out. Is there an easy way to do this?
Your answer
Follow this Question
Related Questions
Struggling to get the rotation the player is moving in. 1 Answer
How to make an object rotate in the direction using horzontal and vertical input axis? 0 Answers
Applying multiple rotations 1 Answer
Torque rigidbody toward desired rotation on two axes ignoring Y axes? 0 Answers
How could I make the children of an object face the direction it is moving on the y-axis? 0 Answers