Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Virtual camera with look at target - how to smooth back to default rotation?

Discussion in 'Cinemachine' started by ndever, Apr 28, 2022.

  1. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    Hi,

    I use a virtual camera with one look at target. The target can move in 2D but it is a 3D game world.. I'd like to create a kind of sticky camera effect where the camera tries to return to its default rotation relentlessly. So when the target object enters the soft zone at the edge of the screen, the camera rotates a bit but when target exits the soft zone, the camera rotation returns to the default rotation.

    I tried to play with the different settings but haven't find anything that would create such an effect. Is it possible that way or am I in need of a custom script?

    Thanks,
    David
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I'm not quite grasping what you're trying to do. Some pictures or video would help here, I think.
     
  3. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    Sure, here's a super basic picture of the situation:

    upload_2022-5-4_23-50-27.png

    The sphere can move left or right, up or down and cannot leave the given screen. What I'm trying to do is when it enters the edge (dead zone in this case), make the camera rotate a bit toward it. As soon as the sphere leaves the dead zone, I'd like the camera to reset to its default position which is all rotation values at zero.

    My question is can I make this happen via a virtual camera setup somehow or must I come up with a script for this?

    I hope it's more clear now, let me know if you have any more questions.
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    ok, so the sphere is free to move around, but at the edges of the frame, in the soft zones, it pulls the camera along with it a little as if on a spring, until it snaps out of frame, and the camera then returns to its resting state. And you want the camera to rotate, not move parallel to the sphere's motion. Is that right?

    There is nothing out-of-the-box I can think of that will do that.

    I think you'll have to make a custom script that monitors the vcam's rotation, and when it passes a threshold you set the LookAt target to null and then manually slerp the camera back to its original rotation over the course of a few frames.
     
  5. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    Yes, that's it. Can I use events when the target sphere enters or exits the soft zones?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    CM doesn't send any events when the target interacts with the soft zone. I think you just need to poll the vcam's transform, and when the rotation exceeds a threshold, you do the thing.
     
  7. ndever

    ndever

    Joined:
    Apr 22, 2017
    Posts:
    15
    OK, thanks for looking into this!