Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Solved] Character Controller facing direction problem

Discussion in 'Physics' started by Metirof, Jan 18, 2020.

  1. Metirof

    Metirof

    Joined:
    Feb 5, 2018
    Posts:
    21
    Hello,

    Im making an endless runner game, and im trying to get the player to face direction of the location transform while switching lane, i searched and i followed some tutorials but for some reason, it doesnt work on my case, the player start "Shaking" as soon as i switch lane (see video on the link below)


    Here is the part of code that is responsible of the rotation

    under Update() function :

    Code (CSharp):
    1.         //rotate player
    2.         Vector3 dir = controller.velocity;
    3.         if (dir != Vector3.zero)
    4.         {
    5.           dir.y = 0;
    6.           transform.forward = dir;
    7.           transform.forward = Vector3.Lerp(transform.forward, dir, TURN_SPEED); // smoother
    8.         }
    used vars:
    private const float TURN_SPEED = 0.05f;

    under Start() function
    controller = GetComponent<CharacterController>();


    And here is a screenshot of the character controller settings :


    Thank you,
     
  2. Metirof

    Metirof

    Joined:
    Feb 5, 2018
    Posts:
    21
    It turns out that the Z value of the center of Character Controller was the problem. it should be set to 0