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

Camera-trigger collisions

Discussion in 'Scripting' started by MadboyJames, Nov 18, 2017.

  1. MadboyJames

    MadboyJames

    Joined:
    Oct 28, 2017
    Posts:
    262
    Hi, so first off, I wasn't sure how to word my title, so sorry about the vagueness. Second, I am trying to make a box that constrains the camera when the camera enters it. The application of this is that the camera follows the player on the y axis (so when they jump) unless the camera is in between rooms, in which case the camera should not follow the player on the y axis if they jump, because the viewport would show a bit of the room above the second room. In short I want this to minimize the camera wandering. The following code was attached to the trigger object. The problem is it always returned true even if I was nowhere near the collision box.
    Code (csharp):
    1.  if (camera.rect.xMin < bounds.max.x || bounds.min.x < camera.rect.xMax || camera.rect.yMin < bounds.max.y || bounds.min.y < camera.rect.yMax)
    2.                 print("true");