Search Unity

Question Cinemachine follow player on planete

Discussion in 'Cinemachine' started by Cirlu, Aug 30, 2022.

  1. Cirlu

    Cirlu

    Joined:
    Oct 3, 2020
    Posts:
    9
    Hey there,

    I'm trying to setup a camera and the behaviour that the player follow the camera direction when we move it ( like on the brackeys 3rd person video tuto ) but on a planet.

    All the cinemachine setup is all good i guess, the problem i have seems to be when i add the cam.eulerAngle.y to the targetAngle on my player movement script. At the start it's working fine but more i go far on the planet, more it's going crazy. I'm pretty sure there is some math to do there to correct the angle to share from the camera to targetDirection, i already tried some stuff but i'm in a front of a wall here...

    If somebody have some tips, knowledge to share it will help a lot,
    Thanks !

    upload_2022-8-30_23-52-40.png
    upload_2022-8-30_23-45-21.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You have to work in local axes and then apply the camera's rotation to convert to worldspace.

    Have a look at the SphericalSurfaceFollow Cinemachine sample scene. It implements player movement on a planet, and you can use it as an example.
     
    Cirlu likes this.
  3. Cirlu

    Cirlu

    Joined:
    Oct 3, 2020
    Posts:
    9
    Hey Gregory, thanks so much for the fast reply, i didn't knew sample scene were available that's great !
    Massive work with Cinemachine, i was using my own camera follow script and a feel stupid now.