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

How to make camera focus on moving object and change what object to focus on

Discussion in 'Scripting' started by Raelin_, Jul 16, 2014.

  1. Raelin_

    Raelin_

    Joined:
    Jul 16, 2014
    Posts:
    20
    Im new to unity and i currently have a bunch of planets(all gameobjects) rotating around a sun(also a gameobject) and im trying to make it so when i click in one of the planets the camera will zoom in on it, and im trying to get it so when i scroll out it will pull the camera away from the planet as well. anyone know how I can do this? also, is it possible to make it so once a planet is selected i can rotate the camera 360 degrees up and down the planet?

    EDIT: Forgot to say im using Javascript
     
    Last edited: Jul 16, 2014
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    You can do this by adjusting the smoothFollow camera script to switch it's targets on a mouse press and lerp the camera between the current target and the new target... All my code is in C# and has a lot of custom code specific to our game so I wont post it here... Can't quite remember ( been away from unity for a couple of months ) but I think the smoothfollow script comes with the built in unity script assets...
     
  3. Raelin_

    Raelin_

    Joined:
    Jul 16, 2014
    Posts:
    20
    Thanks :D