- Home /
Camera location to camera location animation
I am needing a bit of help with a script that will allow an animation from view point to view point with a camera, or series of cameras. For an example see:
http://www.buchhofer.com/upload/files/labs/drexel/
Brilliant architectural viz work by Dave Buchhofer!!
Thanks!
Apologies about the ambiguity - the reality is that i am really looking for "best practice/method" as much as "best solution." The reason for the link is to hopefully explain the intent. Looking into your answer this weekend, and will post back if i have any q's. Thank you for the response!!
Answer by skovacs1 · Oct 13, 2010 at 05:18 PM
You should be more specific about what exactly you need help with. I have no idea what exactly you are asking for.
From what I saw, all that they did was use Lerp and LookAt.
var lookAtTarget : Transform; //What to look at var current : Transform; //Where to start var transitionTime : float = 1.0f; //Time to take to transition
function Start() { //Initial positioning if(current) transform.position = current.position; //position if(lookAtTarget) transform.LookAt(lookAtTarget); //look at target }
//Call this with the transform to move to. static function MoveCamera(target : Transform) { if(!target || current == target) return; //Nowhere to go if(!current) { //Nowhere to start from, so initial positioning transform.position = target.position; //position if(lookAtTarget) transform.LookAt(lookAtTarget); //look at target } else { var control : float = 0; //Amount along transition while(control < 1.0) { //Continue until we reach the destination control += Time.deltaTime/transitionTime; //move along transition transform.position = Vector3.Lerp(current.position, target.position, Mathf.SmoothStep(0.0, 1.0, control)); //Smoothing optional if(lookAtTarget) transform.LookAt(lookAtTarget); //look at target yield; //wait } } current = target; //we're now at the target's position; }
If you want to instantly switch camera position and orientation to some other position/orientation, you could use transform.position = target.position; transform.rotation = target.rotation;
If you want to actually switch to a different camera, you could enable/disable cameras with camera.enabled = false; target.camera.enabled = true;
or something like that.
Answer by Bill Blakesley · Mar 01, 2011 at 10:05 PM
I keep getting compile errors with this script. This is javascript correct?
Your answer
Follow this Question
Related Questions
Unity camera troubles 1 Answer
first and thirt person view 1 Answer
Multiple Monitor Cave Setup with three Cameras 2 Answers
How do I render to texture only a part of the cameras view? 0 Answers
Camera looking at players face 2 Answers