Player keeps rotating

This is my player script for moving and rotating but my problem is the player keeps rotating when i’m not pressing anything.

using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {

    public float moveSpeed = 5;
    public float moveSpeedSmooth = 0.3f;
    public float rotateSpeeed = 180;
    public float rotateSpeedSmooth = 0.3f;
    public float jumpSpeed = 20;
    public float gravity = 9.8f;

    float currentForwardSpeed;
    float forwardSpeedV;

    float targetRotation;
    float currentRotation;
    float rotationV;

    CharacterController controller;
    Vector3 currentMovement;

    void Start ()
    {
        controller = GetComponent<CharacterController>();
    }


    void Update ()
    {
        //transform.Rotate (0, Input.GetAxisRaw ("Horizontal") * rotateSpeeed * Time.deltaTime, 0);

        targetRotation += Input.GetAxisRaw("Horizontal") + rotateSpeeed * Time.deltaTime;
        if (targetRotation > 360)
            targetRotation -= 360;
        if (targetRotation < 0)
            targetRotation += 360;
        currentRotation = Mathf.SmoothDampAngle (currentRotation, targetRotation, ref rotationV, rotateSpeedSmooth);
        transform.eulerAngles = new Vector3 (0, currentRotation, 0);

        currentForwardSpeed = Mathf.SmoothDamp (currentForwardSpeed, Input.GetAxisRaw("Vertical") + moveSpeed * Time.deltaTime, ref forwardSpeedV, moveSpeedSmooth);

        currentMovement = new Vector3 (0, currentMovement.y, currentForwardSpeed);
        currentMovement = transform.rotation * currentMovement;

        if (controller.isGrounded == false)
            currentMovement -= new Vector3 (0, gravity * Time.deltaTime, 0);
        else
            currentMovement.y = 0;

        if (controller.isGrounded &&     Input.GetButtonDown("Jump"))
            currentMovement.y = jumpSpeed;
           

        controller.Move(currentMovement);
    }
}
 targetRotation += Input.GetAxisRaw("Horizontal") + rotateSpeeed;

I just tested it and took out the time.delta time bit “rotateSpeeed *Time.deltaTime

That is what is continuously animating/rotating it.

1 Like

Thanks so much, it worked.

1 Like

You are welcome!

shouldn’t that be “input * speed” in any case?

I’m not sure tbh, i got this from a Youtube video and from what i have learned, we use delta time so that when we start the game the player stays at the same rotation we put. This may or may not be true and my explanation probably didn’t make any sense. But i’m not planning to be a programmer anyways.

Yes you should be multiplying them, this is probably what you want:

targetRotation += Input.GetAxisRaw("Horizontal") * rotateSpeeed * Time.deltaTime;