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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Trying to change camera focal point based on objects near frustum

Discussion in 'Scripting' started by mikesawicki64, Mar 21, 2015.

  1. mikesawicki64

    mikesawicki64

    Joined:
    May 12, 2014
    Posts:
    33
    I'm wondering how to approach this issue (3d side scroller) c#

    Right now my camera is focused on targets either in front of or behind the player, depending on which direction the player is running. If there is an enemy, I will focus on a point in between the player and the enemy.

    What I'm having trouble with is this: I'd like to change the camera's point of focus slightly before the enemy is in camera view. Sort of like, you're running, you're running, now suddenly the camera adjusts to show there is an enemy on the path before the enemy is in its own attackPlayer range

    Checking the distances between the player and all the enemies in a large environment seems like its over-kill and way too processor intensive.

    What I think would work well is - if there's an enemy within 5 units (or w/e) of the camera's frustum, so right outside the view, switch the camera's focus to the new position (which would be half way between the player and the enemy). Does anyone have any suggestions on how this could be accomplished?
     
  2. mikesawicki64

    mikesawicki64

    Joined:
    May 12, 2014
    Posts:
    33
    bump - any ideas?