I have this extremely simple code right here for a velocity based movement for a retro shooter clone. The mouse movement is locked to the Y axis of the player so there is no X camera rotation. When the X and Z velocities are applied independently there isn’t a problem, but when they are applied simultaneously, it rotates the Y axis of the character as if it was affecting the mouse look.
I believe it has a correlation with how I apply the velocity to the X and Z axis, with the line ```
theRB.velocity = (moveHorizontal + moveVertical) * moveSpeed;
PlayerMovement Code:
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody theRB;
public float moveSpeed = 5f;
public Vector3 moveInput;
private Vector2 mouseInput;
public float mouseSensitivity = 10f;
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
//Movement
moveInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Vector3 moveHorizontal = transform.right * moveInput.x;
Vector3 moveVertical = transform.forward * moveInput.z;
theRB.velocity = (moveHorizontal + moveVertical) * moveSpeed;
//Mouse Control
mouseInput = new Vector2(Input.GetAxisRaw("Mouse X"), 0) * mouseSensitivity;
transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y + mouseInput.x, 0);
}
}