- Home /
Question by
klaermans32 · Jul 03, 2020 at 10:35 PM ·
movementmouselookaiming
What is the right way to aim in a FPS depending on mouse position
So the way i rotate my player towards the mouse (basically aiming in a fps) is like this:
Vector2 mouseInput = controls.Player.MouseAim.ReadValue<Vector2>();
float yaw = speedH * Input.mousePosition.x/10;
float pitch = -speedV * Input.mousePosition.y/10;
//clamp so the player can not look completely down or up
pitch = Mathf.Clamp(pitch, -60f, 15f);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
This works but it doesnt work the way it is supposed to. When my mouse reaches the left or right border of the screen the player can not rotate further. Now i wonder how you would normally do something like this, so that you can always keep rotating if you'd keep moving your mouse.
Comment
Best Answer
Answer by UnityedWeStand · Jul 03, 2020 at 11:28 PM
The normal approach is to lock the cursor in the middle of the screen. See this post for details