Face movement of direction problems

I’ve been trying to make this work for a few hours and I just can’t figure it out.
I wrote out a script myself, but as soon as I stopped the character would go back to facing the first direction it was in.

I googled a solution, got another script that was supposed to fix this, but it has the exact same problems. Same happened the third time I tried.

Am I missing something here? Why does my player keep going back to its default position?

using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;

public class Controls : MonoBehaviour {
    public float speed;
    private Rigidbody rb;
    Vector3 movement;
    public float moveHorizontal;
    public float moveVertical;

    public Vector3 jump;
    public float jumpForce;

    public bool isGrounded = true;

    private Vector3 curLoc;
    private Vector3 prevLoc;
    private float curLocX;
    private float prevLocX;
    private float curLocZ;
    private float prevLocZ;

    void Awake(){
        rb = GetComponent<Rigidbody> ();
        jump = new Vector3(0.0f, 2.0f, 0.0f);
    }
       
    void OnCollisionStay() {
        isGrounded = true;
    }

    void Update () {
        ControllPlayer();
    }

    void ControllPlayer()
    {
        float moveHorizontal = Input.GetAxisRaw ("Horizontal");
        float moveVertical = Input.GetAxisRaw ("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

        if (transform.position != prevLoc) {
            transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (movement), 0.15F);
        }

        transform.Translate (movement * speed * Time.deltaTime, Space.World);


        //        if (Input.GetKey (KeyCode.Space) && isGrounded == true) {
        //            rb.AddForce (jump * jumpForce, ForceMode.Impulse);
        //            isGrounded = false;
        //        }

    }

    private void InputListen() {
        Debug.Log (transform.position.x);

        prevLoc = curLoc;
        curLoc = transform.position;

        prevLocX = curLocX;
        curLocX = transform.position.x;

        prevLocZ = curLocZ;
        curLocZ = transform.position.z;
    }
}

Slerp’s 3rd parameter is clamped [0…1]
Sorry, I’m not sure how to improve the script for you other than tidbit of information. You keep re-assigning “.15” to the 3rd parameter.

Ended up discovering the problem was in my if statement that kept calling the rotation after the character had stopped moving.

I fixed it with this

        if (movement.sqrMagnitude > 0.1f && isGrounded){
            transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (movement), 0.15F);
        }

Cool, and that works even though the value is always “.15”? Interesting. Glad ya got it working, regardless :slight_smile: