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

Question Detect target leaving camera boundaries

Discussion in 'Cinemachine' started by xvivax, Dec 6, 2021.

  1. xvivax

    xvivax

    Joined:
    May 16, 2017
    Posts:
    5
    Hi all,

    New to Cinemachine. Just wonder is there any event which detects when target (player) leaves the virtual camera boundaries?

    If more info needed:
    Player falls down when hitting the enemy. At some point I stop following the player (vcam.Follow = null) and player leaves camera boundaries.

    My solution would be to place the box collider under virtual camera and then using OnTrigger event detect when the player leaves the boundaires, but maybe there is more elegant way to do it?

    Thank you
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    There is no built-in event for this in CM - and even if there were it wouldn't work if you set the Follow target to null, because you're telling CM to forget about that target.

    Instead of a box collider, you can have a script that monitors the angle between the camera +Z axis and a ray going from camera to target. If the angle is bigger than the camera's FOV, then the target is offscreen.
     
    xvivax likes this.