Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

How to Transition to a different camera after clicking on text or a "button"?

Discussion in 'Cinemachine' started by soleron, Dec 13, 2017.

  1. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    216
    Not sure if this is a proper usage for it, but here it goes.

    I want to use Cinemachine for my game and I want to transition from one camera to another.

    3 different cameras, one meant to show home screen items i.e. "Play" and "Settings" text, the other focuses and automatically follows the game character after one hits the play button, and a 3rd camera may point to a different direction for the game settings menu. (i.e. look up to the sky while some text slides in)

    I understand that Cinemachine and Timeline allow that functionality without scripting. Is that correct?

    If so,
    could you please guide me through this with some general directions?
    (i.e. do this there, then load it there)
    Or point me to relevant tutorials?
    Or perhaps suggest a different more simple way to do this?

    I am not a very experienced Unity user when it comes to scripting and creating animations and triggers in the engine. I have some experience with VS Blend where event triggers and animations feel a bit more straight forward.

    i.e. create an animation, and then simply call it by name through the event menu after defining an action that triggers it. How could this done in Unity with Cinemachine cameras?

    Thank you very much in advance.
     
  2. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    Hi @soleron

    You can do a heck of a lot with Timeline and Cinemachine without coding but not everything.

    Cinemachine was designed in a way where you make multiple virtual cameras and turn them on and off to blend/cut between them to reinforce the gameplay or whatever else you'd like to do custom camera behaviours on.

    In your setup, you'd like to make the camera do different things based on gameplay / front end / etc. Awesome, this is easy!

    Create as many different cameras based on the events you'd like the camera to do something specific for. Then, it's as easy as turning them on and off whenever those events happen. Cinemachine will use the default blend to transition between the cameras. You can find that on the Cinemachine Brain, most likely on your Main Camera:
    upload_2017-12-14_11-50-37.png

    If you'd like different blends between cameras, simply hit that + on the Camera Cut Event panel and whip up whatever custom blends you'd like.

    Make a bunch of cameras, have them all turned off but whatever camera you want to be the first one active, then as the different events happen in your game, simply turn that camera on. We made this as easy as possible!

    How to activate a game object:
    https://unity3d.com/learn/tutorials/topics/scripting/activating-gameobjects

    How to create a camera and switch targets (from the example projects
    // Create a virtual camera that looks at object "Cube", and set some settings
    vcam = new GameObject("VirtualCamera").AddComponent<CinemachineVirtualCamera>();
    vcam.m_LookAt = GameObject.Find("Cube").transform;
    vcam.m_Priority = 10;
    vcam.gameObject.transform.position = new Vector3(0, 1, 0);



    Let us know how it goes. I know as a newcomer to Unity there's a lot of different things to learn but you'll find out you can get up and going really quickly and have a pile of fun.
     
  3. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    216
    Wow! Thank you very much, I will get to it right away and let you know!

    Here's the image from my menu btw.
    If anyone wants to know more about the game feel free to visit the FB page of Terataki.
     
  4. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    105

    Hi,

    I feel like an idiot but I also wanted to do the same as soleron but I don't get how to do it. I tried to .SetActive() the camera but it gives me a compiling error... Since this doesn't seem to be the way: How am I supposed to activate/deactivate the virtual cameras?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Try vcam.gameObject.SetActive(true)
     
    MSachs likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Just a quick correction: the Camera Cut event is a notification when the current virtual camera changes without a blend. I think Adam meant to say that you need to create a Custom Blends asset, and hit the little plus in there.

    upload_2018-2-8_9-31-25.png
     
  7. MSachs

    MSachs

    Joined:
    Nov 22, 2017
    Posts:
    105
    Thanks! :)
     
  8. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    Yes, thanks Gregory - wrong image

    @MSachs - here's a custom blend setup example - note there's wildcards too
    upload_2018-2-13_19-20-59.png
     
  9. terrijaki

    terrijaki

    Joined:
    Apr 17, 2020
    Posts:
    2
    Hi, i am so sorry but I have not much experience with Unity :oops: but i hope you can help me :)

    i want use the cinemachine for moving only one camera to different Game Objects per Mouseclick on a Button (here i made for example a new Sprite on a 3D Cube)
    And i also want to set a distance to the Game Object. Because i need different views of Game Objects but only with one camera (it should looks like the camera zoom/move to an Object and then to another object).
    Is there a possibility to do that? Or is there any way ? Thank you so much:rolleyes:
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @terrijaki Yes. The setup with Cinemachine is to have a single camera (with a CM Brain on it), and multiple virtual cameras that target different things, and represent positions for the main camera. When you activate a virtual camera, the main camera will blend smoothly to the position of the virtual camera.

    Look at some of the Cinemachine example scenes (you can import them from the Package Manager) to see how it's set up. In particular, the Transposer sample scene shows one camera with multiple (deactivated) virtual cameras. Play the scene, and activate the virtual cameras manually. The main camera will blend smoothly between the states defined by the virtual cameras.
     
  11. terrijaki

    terrijaki

    Joined:
    Apr 17, 2020
    Posts:
    2
    AH, perfect thank you so much :)
     
  12. abhisheksingh_a97

    abhisheksingh_a97

    Joined:
    Dec 26, 2018
    Posts:
    7

    Which Transposer Scene are you talking about? I can't find it in the asset store. Can you please provide the link?
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Not the asset store. The Unity package manager:

    upload_2020-6-27_20-39-53.png

    upload_2020-6-27_20-40-36.png
     
  14. abhisheksingh_a97

    abhisheksingh_a97

    Joined:
    Dec 26, 2018
    Posts:
    7
    Sir, I want to create something like this using cinemachine ,
    is it possible?


    if so, Can you explain it to me how to do it?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Yes. I would do it with a virtual camera with Framing Transposer in Body, and DoNothing in Aim. Set the Follow target to be an invisible object which will serve as the pivot point.

    Write a custom script that you attach to the virtual camera. In that script, respond to mouse movement by modifying the vcam's X and Y rotation. Respond to middle-button dragging by moving the pivot point. Respond to mouse wheel scrolling by adjusting vcam.GetCinemachineComponent<CinemachineFramingTransposer>().m_CameraDistance.
     
unityunity