Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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