- Home /
Player rotation
So I have this script that I used for a 3D game, but I wanted to use it on a 3D side scroller
When I move to the right(forward) the player looks at the screen (right) instead of looking forward
And when I move the the left(backwards) the player looks away from the screen instead of looking backwards.
How can I fix this?Thanks in advance!
void Update () {
Vector3 horizontalInput = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
if (horizontalInput.magnitude > 1)
horizontalInput.Normalize ();
Vector3 targetHorizontalMovement = horizontalInput;
targetHorizontalMovement.y = 0;
targetHorizontalMovement.Normalize ();
targetHorizontalMovement *= horizontalInput.magnitude;
currentMovement = Vector3.SmoothDamp(currentMovement, targetHorizontalMovement * movementSpeed,ref currentMovementV, moveSmoothUse);
if(new Vector3(currentMovement.x,0,currentMovement.z).magnitude > 1){
targetRotationQ = Quaternion.LookRotation(new Vector3(currentMovement.x, 0, currentMovement.z));
transform.rotation = Quaternion.Euler(0,Mathf.SmoothDampAngle(transform.rotation.eulerAngles.y, targetRotationQ.eulerAngles.y, ref rotationV, rotateSpeedSmooth),0);
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220611225922im_/https://answers.unity.com/themes/thub/images/avi.jpg)