Search Unity

Cinemachine Luigis Mansion 3 Style Camera

Discussion in 'Cinemachine' started by alber_developer, Jan 14, 2022.

  1. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    I'm new to Cinemachine, so forgive me if this is a stupid question or has been answered before. I am trying to create a camera system for a 3d platformer using Cinemachine that is similar to Luigi's Mansion 3. Here you can see an short video (from minute 5 to 6:30 aprox):


    I have thought about to create a "horizontal" dolly track for each area, and a trigger collider between doors to translate the camera... but I look this solution very heavy and too difficult to implement. I tried that and so the result wasn't that I've expected. This may there another simply solution with Cinemachine?

    PS: Some areas are 'vertical', so the technique must be the same but in Z axis.

    Thank you so much!
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You can achieve this with a FramingTransposer, Confiner and CinemachineTriggerVolumes.

    Check these example scenes: 2DConfiner, 2D Zoom, 2DTargetGroup, Trigger volume, CameraMagnets.

    You can get our example scenes from the Package Manager. Click on Cinemachine, and download our samples.
    Samples.png

    If you get stuck or need more info don't hesitate to reach out ;)
     
    Last edited: Jan 14, 2022
    Gregoryl likes this.
  3. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    okay, thank you for the initial resources to get started. I'll try it.

    Best regards.
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Were you able to setup your cameras correctly? Let us know if you are stuck at and need help ;)
     
  5. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    Hello gaborkb, I didn't get it at all, my environment is in fact 3D, I changed the confiner2D for confiner3D and the following zoom doesn't act as I want.

    Thank you!
     
  6. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Please provide more information on what you got (images, setups, descriptions), and what's not working / where you are stuck. :)
     
  7. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    Hello, I've created and empty project with the basics.

    For the next post: I need to create a check list of all things that I believe I need.

    The first step is collision before player arrives to wall, first screen shot, that think isn't working:



    What I want:


    I'm agree with I have another solution, using a CinemachineConfiner (3D), but this solution is very hard to implement, because I need to take care with the size of each room, and set exactly "the margins" between walls.

    As I sayed before, this is my first step (really the second step) the camera already follows the player as I need :D

    Thank you so much!

    Regards.
     

    Attached Files:

  8. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    One option is to set it up for every room. Each room could have its own vcam with its own confiner. This way, you'll have a lot of control.
    But if your behaviour is the same for each room, then you could write a CinemachineExtension script that does not allow the camera to get too close to walls.

    Great ;)
     
  9. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    @gaborkb Can you illuminate me a bit little more about how to do that? :rolleyes:

    Thank you!
     
    Last edited: Oct 28, 2022
  10. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    You could create a CinemachineExtension script that checks how far the vcam is from some walls, and modifies the position if needed.
    Code (CSharp):
    1. using Cinemachine;
    2. using UnityEngine;
    3.  
    4. public class RepelFromWalls : CinemachineExtension
    5. {
    6.     protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    7.     {
    8.         if (stage == CinemachineCore.Stage.Finalize)
    9.         {
    10.             // TODO: move vcam based on wall proximity
    11.         }
    12.     }
    13. }
    Cinemachine has 4 stages: Body (positioning) -> Aim (rotating) -> Noise -> Finalize. Depending on how you want it, but you can probably run your logic after Body.

    You can also look at CinemachineCameraOffset script for inspiration.
     
  11. alber_developer

    alber_developer

    Joined:
    Jul 2, 2016
    Posts:
    16
    Hi @gaborkb, it's been a long time since I last wrote here, a little over a year, hehe.

    I've finally been able to implement the camera mechanics as I wanted with the tools you gave me from Cinemachine.

    After many tests and given that I will have rooms of different sizes, I have chosen to make a script where I create a volume that occupies the whole room with a box collider, to activate or deactivate the camera of that room and I use the colliders of the lower walls to act as camera confiner.

    Approximate result of what I want, you can see my prototype if you want.

    https://alberdeveloper.itch.io/light-the-path-proto-v1

    PS: I know there is still a lot of work to be done, but the initial results are not too bad.

    Thanks a lot!
     
    Gregoryl likes this.