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. Dismiss Notice

3rd person character controller on a planet

Discussion in 'Scripting' started by Shiv2k3, Aug 4, 2021.

  1. Shiv2k3

    Shiv2k3

    Joined:
    Jun 30, 2019
    Posts:
    112
    So I am trying to create a 3rd person character controller that works on a planet, currently I have the player standing correctly where ever they go by setting the player's transform.up to it their position, but that causes a problem, when you set the transform.up the Y rotation of the player also gets reset, so to fix that I saved the player's y rotation before setting their transform.up than after setting it I added the y value back, but now I need to have the player rotate in the direction the camera is facing so I need help with doing that.
     
  2. chatrat12

    chatrat12

    Joined:
    Jan 21, 2015
    Posts:
    122
    Avoid using Euler angles. It's best to use linear algebra. One possible way to add your yaw is to something like
    transform.rotation *= Quaternion.AngleAxis(angle, transform.up);
    . You'll probably want to get your yaw through a different method though. However, compositing quaternions can be quite powerful.
     
  3. Shiv2k3

    Shiv2k3

    Joined:
    Jun 30, 2019
    Posts:
    112
    Where can I learn to use unity quaternions and learn general lenierar algebra?