Hello! I am trying to work on a player controller to move the player object! I am calculating the move direction with transform.forward and transform.right since the player rotates with the cursor but when in game mode a few seconds in, the transform.forward and transform.right stops updating even when the player object rotates (so the player just moves in one direction D:). What may be causing this stop in update and how do I fix it?
Here are the relevant parts of my code:
private void FixedUpdate()
{
if (canMove)
{
playerMovement();
}
}
void playerMovement()
{
moveVert = Input.GetAxisRaw("Vertical");
moveHori = Input.GetAxisRaw("Horizontal");
Vector3 moveDirection = (transform.forward * moveVert + transform.right * moveHori).normalized;
Debug.Log("transform forward " + transform.forward);
Debug.Log("transform right " + transform.right);
Debug.DrawRay(transform.position, moveDirection * 5f, Color.green);
playerRB.MovePosition(transform.position + moveDirection * Time.deltaTime * playerSpeed);
}
void playerRotation()
{
//based on the mouse input we want to be able to rotate the player and or camera horizontally or vertically
//along horizontally the player and camera should move but horizontally only the camera should move
mouseX = Input.GetAxisRaw("Mouse X") * mouseSensitivity * Time.deltaTime;
mouseY = Input.GetAxisRaw("Mouse Y") * mouseSensitivity * Time.deltaTime;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90.0f, 90.0f);
transform.rotation = Quaternion.Euler(0, yRotation, 0);
mainCamera.transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
}
I’d appreciate any help!