Well, I haven’t found anything related to the way of how I want to rotate my player because I don’t know how to phrase this. Maybe there is an answer out there, but I can’t find it.
Basically this is my issue. I’m making a spaceship first/third person shooter, so the player is constantly moving forward. What I want is a script, a tutorial or a link that rotates the player to where the cursor is.
Lets say that the center of the screen is (0,0), the upper left corner is (-1,1) and the bottom right (1,-1)
Some examples:
If the mouse is at (0,0) in the screen the player is not rotating.
If the mouse is at (1,0) in the screen the player is doing a sharp rotation to the right.
If the mouse is at (0,1) in the screen the player is doing a sharp rotation up.
If the mouse is at (0,-0.4) in the screen the player is rotating down.
What I have (and don’t want):
I have a script that rotates the player the way I want as long as I’m moving the mouse. As an instance: If I want to rotate right, I have to keep moving the mouse to the right. The faster I move it, the more it rotates.
These are the lines of the script that make that part functional:
//declarations
public float RotationVariable = 1.0f;
public float RotateLeftRight = 0.0f;
public float RotateUpDown = 0.0f;
//end declarations
void Update()
{
transform.Rotate(-RotateUpDown, RotateLeftRight, 0.0f);
RotateLeftRight = Input.GetAxis ("Mouse X") * RotationVariable;
RotateUpDown = Input.GetAxis ("Mouse Y") * RotationVariable;
}
If you happen to answer this question, can you please tell me how to name this kind of rotation? I would like to post a tutorial with this in case I don’t find anything.
Thank you and sorry for the long post.