I started a new project. It's a simple FPS game. Tutorials are often outdated so i started to write it on my own.
The player's movement is fine. The camera's is not. I store all my data values in a data class
public class CameraMovementData : CameraCommonData // datastore
{
public float InputHorizontal { get { return Input.GetAxisRaw("Mouse X"); } } // horizontal mouse input
private float yMin = -70; // player looks down - minimum
private float yMax = 70; // player looks up - maximum
public float InputVertical { get { return Mathf.Clamp(Input.GetAxisRaw("Mouse Y"), yMin, yMax); } } // vertical clamped mouse Input
public float Sensitivity { get { return 30; } } // mouse sensitivity
public Vector2 Movement { get { return new Vector3(InputHorizontal * Sensitivity * Time.deltaTime, -InputVertical * Sensitivity * Time.deltaTime); } } // the movement direction of the camera
}
In my controller I have this:
public class CameraMovementController : CameraCommonController // use the values from the datastore
{
private CameraMovementData data; // instance to the datastore
private void Start()
{
data = new CameraMovementData();
}
private void Update()
{
data.PlayerTransform.localRotation = data.Movement.x; // Rotate the player on X
data.CameraTransform.localRotation = data.Movement.y; // Rotate the camera on Y
}
}
So as you can see, I don't know, how to write my rotation in the Update method.
I have to use the localRotation, right?
And what do I have to assign to it, to make it work?
It seems I have to use
Quaternion.AngleAxis();
but I don't know, what to pass in as a second parameter
Quaternion, but you are passing afloat.Quaternion.AngleAxis();I don't know what to pass in as a second parameterlocalEulerAngles. See this answer for a complete code. Just don't like re-posting code unless when really necessary.