Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Cinemachine Metroidvania/Megaman Style Camera

Discussion in 'Cinemachine' started by JonnyRage, Jun 14, 2018.

  1. JonnyRage

    JonnyRage

    Joined:
    May 30, 2018
    Posts:
    4
    I'm new to Unity and 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 2d platformer using cinemachine that is similar to Mega Man, Shovel Knight, or Celeste where the camera kind of snaps to the new area/level once the player crosses a certain boundary and there is even a little bit of slow down during this transition. I also want to be able to have irregular sized rooms such as narrow corridors you might fall down or traverse or odd shaped rooms. I tried creating multiple vCams to handle this. For example in my prototype I have one large horizontal room and then a drop off down a narrow hallway. I created two separate polygon collider 2d components for each room and marked them as triggers and also 2 vCams. Let's call the objects that have the colliders "Starting Room" and "Big Drop". I set these as the Bounding shapes on each of my cameras named respectively 'vCamStartingRoom' and 'vCamBigDrop' the confine mode is 2D and confine screen edges is checked. The priority is the same on both cameras (the default priority of 10). When the player collides with the trigger 'Big Drop' I have a script attached that was trying to do the following:


    public class VCamController : MonoBehaviour
    {
    private GameObject startcam;
    private GameObject transitionCam;
    void Start()
    {
    startcam = GameObject.Find("vCamStartingRoom");
    transitionCam = GameObject.Find("vCamBigDrop");

    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
    if(collision.CompareTag("Player"))
    {
    Debug.Log("The Player Entered");
    startcam.SetActive(false);
    transitionCam.SetActive(true);
    }

    }
    }

    It seems like it switches the camera but the 'vCamBigDrop' does not respect the confining space because the orthographic size of the camera is larger than the confinement area and I don't know how to get it to be the correct size of the narrower hallway since it is set to follow the player. The result is that the camera shows areas of the level it is not supposed to. How can I achieve this and the 'snapping' effect I described above? I'm sure there is a better way to go about this. I also thought of using a state driven camera and somehow switching between cameras based on the room the player was in, but that didn't seem to work well for me either since it required animator. Any help would be appreciated. Some Examples of the types of maps I would like to be able to implement from attached. Celeste_Maps_Ch3_Sec2_(w3000).jpg MegaManIII-SnakeMan.png Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,217
    Why can't you just make the orthographic size of the big drop vcam small enough to fit in the space?
     
  3. JonnyRage

    JonnyRage

    Joined:
    May 30, 2018
    Posts:
    4
    That makes sense thanks. I did try that initially, but I think there was some other issues going on where it kept throwing errors saying my camera variable was a null reference so it wasn't making the switch properly. I believe I resolved that. Also, the fact that I couldn't really place the camera where I wanted since it was set to follow the player was throwing me off. What I did was temporarily raise the priority of the camera I wanted to work with and then moved the player to the area it was confined to and resized the camera there. Is there any way I can change the orthographic size and not be as zoomed in? Also, do you have any ideas as to how I would achieve the snapping transition I described above? Is toggling the active status the best way to handle this, or is it better to change the priority of the camera?
    Thanks again for the help.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,217
    Changing the ortho size is the same thing as zooming. If you didn't zoom, you'd see outside the game area! If you don't mind that, then you could just make the bounds collider a little bigger than the game area, and size the camera to fit in that.

    Toggling the active status or the priority will give the same results visually. The difference is that when the camera is inactive it consumes less resources, so that might be of interest to you.

    You could do the snapping by using a custom blend curve when blending to the second camera. You'll need the latest CM (available from Package Manager on Unity 2018) for that feature.
     
    Last edited: Jun 14, 2018
  5. JonnyRage

    JonnyRage

    Joined:
    May 30, 2018
    Posts:
    4
    That's kind of what I figured...I had a feeling I was asking a stupid question but I went for it anyway! If the zoom level is too much then I can go the route you said, or I could scale my tile sizes or character sizes in combination with the orthographic view until I get a look I am happy with. I will look into downloading the latest CM so I can experiment with the custom blend curve. Are there any tutorials or a section in the documentation that you could point me towards to help me get started with that?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,217
    No tutorials that I'm aware of, but it's pretty straightforward. To make a custom blend curve (in this example for the brain's default blend) you do this:

    upload_2018-6-14_15-49-11.png

    This will expose a curve editor which you can click on and draw the curve you want:

    upload_2018-6-14_15-50-5.png

    To make custom blends for specific vcams you would first create a custom blends asset:

    upload_2018-6-14_15-51-46.png

    Then add an entry for each custom blend you want to define:

    upload_2018-6-14_15-52-49.png
     
  7. JonnyRage

    JonnyRage

    Joined:
    May 30, 2018
    Posts:
    4
    Very Helpful thanks! I've installed unity 2018 and I will give it a try once I get the latest version of Cinemachine installed using the package manager.