TL;DR
How to rotate a Vector3 around an axis that is not parallel to the X, Y or Z axes?
Hi! First, I know there are a ton of question similar to this one, but I could not find what I was looking for.
I’m trying to create a 3D-ish top down game. The floor is rotated 40 degrees on the X-axis. I am trying to create an aiming system, where the player can either aim with the mouse or with an analog stick.
when I tried implementing the aiming in 2D and the surface was parallel to the Y-axis, It was just finding the direction vector between the player position and the mouse in world coordinates. but now the ground is tilted and its in 3D.
first I found a vector parallel to the tilted surface that will act as the new forward vector:
aimVector = Vector3.forward;
float groundRotation = -50f;
Quaternion angle = Quaternion.Euler(groundRotation, 0, 0);
aimVector = angle * aimVector;
I tried to find all 4 (forward, back, right, left) so I can try to interpolate between them, but that did not succeed.
Eventually, I want to be able to “project” the mouse position on the surface and have the player facing there.
Any help would be very appreciated, thank you!