- Home /
Rotation of Object on single axis in direction of the mouse position
Okay, I have done a few hours search and found one question with an answer that didn't get what I desired. What I have is a sword, currently has a rotation of (0, 90, 90), and I want that sword to rotate on the x axis to point at the location of the mouse, while the other two rotation axis remain untouched.
For example, the Sword is located at position 0,-1,6 with rotation 0,90,90, and the mouse is currently pointing at 3,3,6 in world space, I want the sword to rotate approx 35 degrees on the x axis. How to I go about finding the required rotation so that the Sword points at that location of the mouse.
Here is a image to help
To get mouse Position in world space, I have a collider located behind the sword, and I shoot a ray from camera in direction of mouse position and collect the location it hit. I dont know if that is correct, but thats what I mean from getting the mouse location.
I have tried transform.LookAt to no luck and many different solutions, so hopefully you understand that can help me out.
Thanks for any future answers.