Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Problem rotating a game object on spherical planets when using cinemachine

Discussion in 'Cinemachine' started by Eustakios, Mar 10, 2024.

  1. Eustakios

    Eustakios

    Joined:
    Feb 23, 2020
    Posts:
    2
    I have spherical planets where the player runs around. As in any game, i want the player to move in the direction the camera is pointing, so what i tried is to get the local rotation of the camera and paste the "y" component into the player's rotation. I use local rotation because since the player stands on spheres, it has to be aligned with the center of gravity. My solution creates a positive feedback loop where the player rotates, the cinemachine camera tries to follow the player's rotation, the camera's position changed so the player tries to follow it... I've been scouting internet but i couldn't find someone with the same problem regarding spherical worlds and camera controls.

    Edit: I use Orbits>Binding mode: Lock to Target so it rotates as the player walks around the sphere.

    Any help is greatly appreciated!!!
     
    Last edited: Mar 10, 2024
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    That's where the problem is. LockToTarget tells the behaviour to position the camera at the specified offset in target-local space, which will rotate with the player. Try another binding mode, for example WorldSpace or SimpleFollow.
     
  3. Eustakios

    Eustakios

    Joined:
    Feb 23, 2020
    Posts:
    2
    I was using LockOnTarget on purpose so when I walk around the sphere, the camera rotates accordingly with the player. How can i achieve the same without lock on target?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    Have a look at the SphericalSurfaceFollow sample scene, it implements what you're looking for. The key is to use the World Up Override field in the CM Brain. Assign that to the player, and then the camera's concept of Up will match the player's.
     
    Eustakios likes this.