- Home /
Question by
axelsevenet · Jun 06, 2021 at 11:29 PM ·
rotationvector3quaternion
How do you rotate an object with Vector that has another vector defining its angle
I have a vector, mouseDir = (mouseY, mouseX, 0), that dictates the movement of my camera based on my mouse movement, and a vector, AttractorPos, that dictates the pull Direction of Gravity (if the gravity is pulling down it is equal to (0, -5f, 0)).
I want the vector mouseDir to adapt to gravity and rotate an object accordingly. for example: if AttractorPos is equal to (0f, 0f, 5f) I would want the final rotation of the object to be Quaternion.Euler(mouseX, 0, MouseY)
The way I rotate the object without gravity adaptation is this:
Target.transform.rotation = Quaternion.Euler(mouseDir);
and I've tried using this to rotate the object with gravity adaptation:
Quaternion eulerAngleVelocity = Quaternion.FromToRotation(Vector3.up, -AttractorPos);
Quaternion deltaRotation = Quaternion.Euler(eulerAngleVelocity * mouseDir * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotation);
But I can't get it to work correctly
Comment