- Home /
Character making an unneeded rotation when first rotating camera around before moving
EDIT: Updated script and description for readability and to make more sense. I'm using Cinemachine for camera, and rewired for input (it does the same with unity's input, so rewired shouldn't matter but mentioning just in case it does). everything works well, my issue is there is a visual bug that for example when you move the character towards you facing the camera, then move the camera around to the back of the player and try to move forward to where the camera is pointing, the players rotation snaps towards you then smoothly rotates a 180 and starts moving forward, instead of just moving forward. only happens if you mess with the camera after moving the player direction.
Anyone know what the issue might be? I've been looking around here and the googles and messed with cinemachine all day.
heres my move and rotate script:
public GameObject Player;
CharacterController charControler;
public Vector3 moveDirection;
public Camera camView;
public float moveSpeed;
public float gravityScale;
public float rotateSpeed;
moveDirection.y += Physics.gravity.y * Time.deltaTime * gravityScale;charControler.Move(moveDirection * Time.deltaTime);
float yStore = moveDirection.y;
moveDirection = (transform.forward* playerInput.GetAxisRaw("MoveY")) (transform.right* playerInput.GetAxisRaw("MoveX"));
moveDirection = moveDirection* moveSpeed;
moveDirection.y = yStore;
if (playerInput.GetAxisRaw("MoveX") != 0 || playerInput.GetAxisRaw("MoveY") != 0)
{
moving = true;
transform.rotation = Quaternion.Euler(0f,
camView.transform.rotation.eulerAngles.y, 0f);
Quaternion newRotation = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
Player.transform.rotation = Quaternion.Slerp(Player.transform.rotation, newRotation, rotateSpeed* Time.deltaTime);
}
![alt text][2]
I Second this Question. I followed a udemy course that had this exact same script, and its bothering me. Been ignoring it for months so if anyone can help that would be freaking awesome. im not using rewired though
Answer by DarkTearStudios · Aug 06, 2021 at 08:43 AM
I fixed it, watched This YouTube tutorial, and changed the entire movement system to that. sucked because I was over 1000 lines into my player controller script and had to change a bunch of stuff to work with the changed values.
Im sure there was a different way that would have saved me that time, but oh well.
Thanks for the help!...