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 How to change freelook rig to face a gameobject.

Discussion in 'Cinemachine' started by Usetheforcemax2, Apr 5, 2024.

  1. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    I have a basic 3rd person shooter freelook camera rig set up. What I want to do is force the player's view to lock onto a target when the key is pressed. It is not as simple as changing the target look at because I want to conserve the third person shooter look at transform set up.
     
  2. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    Basically I would like to go from this
    upload_2024-4-5_18-32-33.png
    To this :
    upload_2024-4-5_18-32-27.png

    on the click of a button
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    It requires more than just changing the look-at target. Really LockOn and FreeLook are completely different camera behaviours, so the way to do it is to implement 2 cameras and swap between them (allowing CM to execute a blend).

    This tutorial is pretty good:


    What version of Unity are you using? I ask because if it's 2022.3 or up and you're just starting to use Cinemachine, it might be a good moment to upgrade CM to version 3.0.1. CM3 comes with a Lock-on Target sample scene that you can look at.
     
    CodeSmile likes this.
  4. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    Aweomse thank you Gregory. I actuallt had seen this video before but I don't to lock onto my target. I would like my perspective and lookat to remain the same. What I'm looking for is an "aim lock on" that can serve as a feature in a third person shooter without a perspective change
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    Something like this?

    aim_mode.gif
     
  6. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    Something like this but that would auto aim to one of the players as well
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    You'll have to describe more carefully what you want, because I don't really understand.

    The way the sample illustrated by my image works, there are 2 camera modes: freelook and aim. In freelook mode, the camera can orbit around the player and face any direction, regardless of which way the player is facing. In aim mode, the camera forward is locked to player forward. Rotating the camera rotates the player. When the player fires while in aim mode, it will hit whatever is under the reticle at screen center. If you enter aim mode while the player is looking in some other direction, the player will rotate to face camera forward.

    How is what you want different?
     
  8. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    Yes sorry for not explaining very well. my character is always in the aim mode. But I want the crosshair which is in the middle of the screen to align with the targeted object (in my example the sphere) while still being in the player's rig. So basically something that could simulate the freelook input to adjust the aiming towards a specific target.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,827
    What exactly is your setup? Can you show the vcam inspector?
     
  10. Usetheforcemax2

    Usetheforcemax2

    Joined:
    Mar 20, 2018
    Posts:
    6
    Finally I managed to solve my issue by switching over from a freecam to a Virtual cam with a third person body. Thank you for your help.