I have the following code that moves the character, however it moves based on world instead of camera facing. I’m using Cinemachine to rotate the camera throughout the game, so how can I change this to get the character to move in relation to camera?
void Move()
{
float xInput = Input.GetAxis("Horizontal");
float zInput = Input.GetAxis("Vertical");
Vector3 dir = new Vector3(xInput, 0, zInput) * moveSpeed;
dir.y = rig.velocity.y;
rig.velocity = dir;
Vector3 facingDir = new Vector3(xInput, 0, zInput);
if (facingDir.magnitude > 0)
{
transform.forward = facingDir;
}
}