Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How Can I Keep an Object Inside a Bounding Box While Rotating the Camera Around It?

Discussion in 'Scripting' started by Melbo_8, May 27, 2023.

  1. Melbo_8

    Melbo_8

    Joined:
    Apr 28, 2023
    Posts:
    4
    Please see the attached image for better details on what I'm trying to achieve.
    I have a camera that can rotate around a target object, but I want it to keep the object with a screen space bounding box by moving back and forth.

    I'm pretty new at C# and not sure how to achieve this, any help or guidance would be greatly appreciated!

    Description.jpg
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Nad_B likes this.
  3. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    303
    Kurt-Dekker likes this.
  4. Melbo_8

    Melbo_8

    Joined:
    Apr 28, 2023
    Posts:
    4
    Thank you for this suggestion. I know how to do a simple raycast to check distance, but how can I raycast the perimeter of an object?
     
  5. Melbo_8

    Melbo_8

    Joined:
    Apr 28, 2023
    Posts:
    4
    Thank you. This is a new concept to me but it seems like the right direction. I'll look into it.