Search Unity

Best way to clamp Cinemachine POV Aim?

Discussion in 'Cinemachine' started by Ranocchio, Dec 4, 2017.

  1. Ranocchio

    Ranocchio

    Joined:
    Apr 25, 2017
    Posts:
    6
    I'm using a virtual camera hard locked to a "head" object and using the POV aim to create a first person effect. I don't want the player to be able to look left or right past the shoulder. What's the best way to clamp the POV camera rotation?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Yeah that’s an oversight that we’re going to correct soon. You can hack it for now by making the Min, Max, and Wrap fields public in the AxisState class.
     
    Last edited: Dec 20, 2017
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    @Kurozatou We've added this feature. It will be in the next release of CM.
     
  4. LilyMcCheddar

    LilyMcCheddar

    Joined:
    Feb 4, 2017
    Posts:
    10
    Hi @Gregoryl, I'm looking for this feature myself, but I haven't found it. Could you tell me how I could clamp the values ? Thank you !
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The easiest way would be to use CM 2.1.12, which is available with Unity 2018.1, via the package manager.
     
    jonathans03 likes this.
  6. LilyMcCheddar

    LilyMcCheddar

    Joined:
    Feb 4, 2017
    Posts:
    10
    @Gregoryl Thank you for your quick reply !
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    If you do upgrade, there is one thing you need to watch out for. Cinemachine is now a Unity Package Manager package, where before it was an Asset Store package. In order to upgrade without issue, you need to:
    1. Make a backup of your project
    2. Delete the Cinemachine asset from your package. Also delete the CinemachinePostProcessing adaptor and the CinemachineExamples assets, if you have them installed. Don't worry about your CM behaviours breaking, they will get fixed up with the next step
    3. Open the Package Manager, and install Cinemachine 2.1.12.
    4. Re-install the CM/PostProcessing adaptor package from the CM menu, if you need it.
     
  8. LilyMcCheddar

    LilyMcCheddar

    Joined:
    Feb 4, 2017
    Posts:
    10
    Thank you @Gregoryl for the additional info. I ended up making it work by exposing the values you mentioned earlier in this thread because I was not ready to upgrade my current project, but I'll be sure to come back to this advice once I do upgrade :)
     
  9. Guneriboi

    Guneriboi

    Joined:
    Nov 25, 2010
    Posts:
    6
    Hey,

    This clamp seems to be a global value. Is there any way to make it local?

    I have a Vcam in a canoe and I'm trying to allow the player to look left, straight and right. However, if the canoe does a 180 degree turn the player is stuck looking backwards.

    Is there any way around this?

    Thank you,
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Yes, this is an oversight in the POV which has been fixed in the upcoming update.

    In the meantime I can give you a quick patch. Drop this modified POV in your assets and it will be available in the Aim menu of the vcam as CinemachinePOV_WithLocalSupport.
     

    Attached Files:

    nathanjams and Guneriboi like this.
  11. Guneriboi

    Guneriboi

    Joined:
    Nov 25, 2010
    Posts:
    6
    Perfect! Thanks for sharing this.
     
  12. GirlLogic

    GirlLogic

    Joined:
    Dec 8, 2018
    Posts:
    4
    2019...Still don't have this option. Documentation shows min and max values, but nowhere in Unity does this property exists. How do I keep my player's head from spinning backwards when they want to have a look around their surroundings with a pov camera?
     
  13. GirlLogic

    GirlLogic

    Joined:
    Dec 8, 2018
    Posts:
    4
    why hasn't this been fixed?
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    This is fixed. Maybe you don't have the latest version of CM? Which version do you have?
     
  15. GirlLogic

    GirlLogic

    Joined:
    Dec 8, 2018
    Posts:
    4
    I have the latest version. After mounds of frustration and searching for solutions, it would appear that in version 2.1.12 this was listed as fixed, but in all further editions, the min max and wrap values do not appear in the UI. Package manager tells me that I am the most up to date with 2.2.8 version of CM. I have tried intstalling each version one at a time versions from 2.1.13 through 2.2.8. Through project manager 2.1.12 is no longer working.
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Here is what I get with CM 2.2.8:

    upload_2019-3-22_16-58-18.png

    Is it possible that you installed the Package Manager version of CM without first deleting an older (AssetStore) version from your project assets?

    If so, you need to do the following:
    1. Uninstall the Package Manger version of CM
    2. Delete the Cinemachine asset from your project, and the CM PostProcessing asset if you have it
    3. Re-install CM from the package manager
     
  17. GirlLogic

    GirlLogic

    Joined:
    Dec 8, 2018
    Posts:
    4
    I never downloaded CM from the asset store before. I did not start to use CM until it was available via the package manager so there isn't a chance that there is a leftover file from the asset store. I have only ever used the package manager. On my version there is no values range, no vertical/horizontal Recentering. Could it be that this feature is only available to paid members. It would seem something so simple as looking around wouldn't be restricted, but my panel looks like this...

    https://gyazo.com/90d0c8f4a6ff698fd505627ef6895fe8
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It looks like you have an old version somehow. What version does it say in Cinemachine/About?
    There are no restricted features in Cinemachine, it's all open-source.
    Try creating a new project and installing latest Cinemachine. What does the POV panel look like then?
     
  19. Darkon_Who

    Darkon_Who

    Joined:
    Jul 22, 2017
    Posts:
    14
    @Gregoryl I wonder if you can please help me...
    I am using a Framing Transposer / Transposer with POV setup for my over the shoulder 3rd person game.

    However as mentioned above here it seems the clamp values for POV are global? Is there anyway to set this to local? I have tried to use the one script you gave me but i think its way to outdated.

    I am on the latest Cinemachine 2.3.5 preview.
     
  20. Darkon_Who

    Darkon_Who

    Joined:
    Jul 22, 2017
    Posts:
    14
    @Gregoryl Basically when i swap to my Transposer / POV setup in the virtual camera, it rotates to face the world forward, not the forward of the target it seems.
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The POV angles are relative to the vcam's parent, or to worldspace if no parent. You can create a parent game object for your vcam, and add a custom script to it to sync its rotation with the target's forward. That might do the job for you.
     
  22. Kadae

    Kadae

    Joined:
    Dec 7, 2013
    Posts:
    52
    So, any good solution to make POV clamps to local in 2021 "from the box" in Unity?
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
  24. Kadae

    Kadae

    Joined:
    Dec 7, 2013
    Posts:
    52
    Works for me now, just looking for a way to do it right.

    I have in my project a first-person view (two cameras), a third-person view (three cameras - inside the car with clamping where car is moving and player is moving inside the car; outside the car with 360 rotating, etc), a ghost-viewer view (one camera). All of this cameras can be switched now by the player and everytime I need to turn off and turn on and tranform and rotate some things when player is outside the car, inside the car, etc... And this cameras are minimum, as I understand. I need a cameras for AI self driven vehicles, AI NPC... Map camera, etc.

    My project have now 5 cinemachine cameras (2 virtual and 3 freelook) with 4 default cameras, and I switching them with a state driven camera, and this is only for player's controller.

    Also I have some jiggle issues with my cinemachine cameras and can't resolve them (tryed everything - fixedupdate, update, lateupdate, with time.deltatime, tryed smart update, fixed for brain camera), just don't know what I'm doing wrong (using new system input, just in case).

    This is an example of some my cameras now in my project, If you interested in what I doing.

    image_005_0000.jpg image_022_0000.jpg image_023_0000.jpg image_024_0000.jpg
     
    Last edited: Oct 31, 2021
  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    It's a little unclear to me why you have to turn transforms on/off etc it you are switching vcams with a StateDrivenCamera. Changing the state should be enough to switch the vcams in that case.

    For your POV camera, if it's inside the car, then you can parent the vcam to the car, put DoNothing in the Body (so that it moves around as a child object), then the range setting in the POV will work automatically relative to the parent. You don't need a custom script.

    If you go that route, then the StateDrivenCamera will also have to be a child of the car, unless you move to a different method of choosing the current active vcam.
     
    Kadae likes this.