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

Question [Resolved] Cinemachine 'Free Look Camera' Player Rotation Issue

Discussion in 'Cinemachine' started by Queen_Kazma, Apr 19, 2022.

  1. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    Hi. In my game, my player has the ability to run on walls and their movement plane/Orientation adjusts accordingly. ( I had to create the players own gravity, separate from the Unity gravity, to accomplish this )

    I've gotten my Cinemachine 'Free Look Camera' to orient itself correctly while running on the walls (by setting the 'Orbits >> Binding Mode' to the 'Lock to Target' value. No other option works as intended. ) What I want to know is how to bind the orbits of the Cinemachine 'Free Look Camera' to the players newly oriented 'up vector' (Which it does currently, using the 'Lock to Target' binding mode) but not the players rotation around that axis?

    Here's an example of the Cinemachine 'Free Look Camera' issue, while on the 'ground' (this applies to every surface, even when running on walls):


    The only code that I'm using to 'alter the players movement based on the camera' is as follows:
    Code (CSharp):
    1.  
    2. movementSpeed = Mathf.Clamp(movementSpeed + acceleration * Time.fixedDeltaTime, baseSpeed, maxSpeed);
    3. movementDirection = new Vector3(horizontalInput, 0, verticalInput);
    4. movementDirection = cameraTransform.TransformVector(movementDirection);
    **Note: I don't believe this will have any impact on the issue I'm experiencing but wanted to provided it for further clarification.

    I'm hoping that someone here might be able to provide me some insight into how to resolve this issue so that I can continue on with the development of my game. :) Thank you in advance to everyone who has any input on this issue.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Have a look at the SphericalSurfaceFollow sample that ships with CM. It's doing pretty much what I think you want. The key elements are: SimleFollowWithWorldUp in the FreeLook and World Up Override in the Brain (set it to be your player).
     
    Last edited: Apr 19, 2022
  3. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    Thank you for the reply, Gregoryl. I've got the World Up Override set to the players transform in my current implementation (below screenshot).

    Additionally, I'm still a bit of a novice at using Cinemachine so I'm not entirely sure of how to look at the 'SphericalSurfaceFollow' that you referenced. Is that a sample project or...? And if so, could you direct me to where and/or how to load/use it?

    upload_2022-4-19_11-46-49.png
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    upload_2022-4-19_11-55-30.png

    Then find the sample in your assets, open the scene, and Play it.

    upload_2022-4-19_11-57-3.png
     
  5. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    So, I loaded up the 'SphericalSurfaceFollow' project and it does exactly what my project is doing, which is the un-intended/undesired behavior. Since that project doesn't have right-joystick camera controls implemented, to emulate the issue I'm experiencing (and want to fix), have the player stand still, move the mouse to the right to see just a bit of the players face, and then hold up/forward on the joystick. The player will spin wildly in place for the duration you're pressing forward.
     
  6. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    I should also mention that, when the 'Orbits >> Binding Mode' is set to 'World Space', it functions exactly as intended...but only when the player orientation is in alignment with world space and provides unintended behavior when the players orientation changes. In short, I need the 'Orbits >> Bindings >> Lock to Target' to function as 'Orbits >> Bindings >> World Space' does, but forcing that behavior relative to the player and not World Space.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Change the binding mode to SimpleFollowWithWorldUp. I mistakenly told you to use Lock To Target before (have edited original post). Is there a problem with using that binding mode?
     
  8. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    ~~Using 'Lock to Target with World Up' produces the same issue.~~

    Edit: I tried the wrong one. SimpleFollowWithWorldUp fixed the issue. Sorry for being dense. XD
    I'm greatly appriciative of your assistance. :)
     
    Last edited: Apr 19, 2022
    Gregoryl likes this.
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Good. All of the "LockToTarget" bindings will position the camera based on the character's forward. If you turn the character, then of course the camera will also turn, and if your controller uses camera forward as input reference then it will spin. SimpleFollow decouples the camera from character forward.
     
  10. Queen_Kazma

    Queen_Kazma

    Joined:
    Feb 5, 2022
    Posts:
    13
    After thinking about it, that does make sense. Again, thank you for the help. :)
     
    Gregoryl likes this.