Search Unity

Preset Camera Locations

Discussion in 'Scripting' started by nm8shun, Jul 28, 2007.

  1. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    OK..Here's what I'd like to do; I'm looking for a bit of advice.

    The project is an environment that the user can interactively fly around in. I've got all that set up. What I'd like to do is setup a collection of buttons (presumably as a GUITexture) that list certain spots in the environment. When the user clicks on one of these buttons, the camera needs to get there.

    I'm assuming the easiest thing to do is to simply have another camera in the desired location and have it work like a jump cut - just cutting to that new camera. Can I get some help on that sort of interactivity script?

    Even nicer though would be the ability to hit the button and have the camera find a path to that new location. I've read of the pathfinder functions on the forums, but I'm unclear if this is really the same idea I'm talking about. Is there something setup to allow this already - if so, could someone please point me there?

    Thanks much!
     
  2. morgansaysthis

    morgansaysthis

    Joined:
    Jan 12, 2007
    Posts:
    245
    one thing you could do is have empty game objects where you want the camera positions to be and have the camera lerp towards the game objects position, this will take the camera in a strait line from where you are to the empty game object in the amount of time you tell it too



    you would just have to name the objects whatever you want them to be " front preset", "rear preset" or w/e and when that button is pressed activate the function that does the lerping, and have the presets transform position be the target for the lerp




    and if youd rather just cut to a different camera, im pretty sure you can just change the camera depths around so the camera you want on would be the higher depth, but you should disable the cameras you arent using if you use this method because im pretty sure even if there not displaying on screen, there still rendering polygons and sucking up memory,but im not sure about that, they might automatically be off if there not on screen
     
  3. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Cool. Thanks for the tip. Currently, I have the camera a child of a Game Object so that it can't fly through the ground or through objects. So with the Lerp method, the camera would simply leave that camera object - fly through objects - and then end up a child of a new Game Object, right?

    So, one more question :oops: would lerping also rotate the camera so that it was facing the appropriate direction?
     
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Check out the package Talzor offered me here. Its the Sh*t man.

    http://forum.unity3d.com/viewtopic.php?p=24333&highlight=#24333

    Sometimes I get slow framerates but Im sure thats due to cramming millions of polygons down the throat of a computer that really doesnt have the required muscle...

    This package is one of my alltime favs- for others reading, its the key to cutscenes. Thanks again Talzor.

    AaronC
     
  5. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    I second that, Talzor's lerping camera package rocks. Remember to comment out the "camera.Render ();" line, it will throw an error till you do. Just rotate the waypoints in the direction you want the camera to point. If you don't want it to fly through stuff, add more waypoints. Also note the handy var for time between waypoints.
     
  6. nm8shun

    nm8shun

    Joined:
    Jul 14, 2007
    Posts:
    476
    Thanks for the suggestions guys. I'll give it a try....