- Home /
Move A Camera Between Two Points Smoothly
Hello everyone, Im trying to move make a transition between a far away camera and a closeup one. They both can move around and be in random places when the player chooses to switch between them. I've tried making it so that there is a third camera that is turned on during this transition and it moves between the two points where the other cameras are smoothly, then changes to the other camera.
Currently it only instantaneously jumps between locations, and I dont know if this will translate the rotation smoothly as well since it is only Vector3? Here is the script just dealing with the transitional camera that I have so far.
var posCam1 : Transform;
var posCam2 : Transform;
var positionCurrent : Transform;
var transitionCamera : GameObject;
var speedAdjust : float;
function Start(){
ReOrient();
}
function ReOrient (){
positionCurrent.transform.position = Vector3.Lerp(posCam1.transform.position, posCam2.transform.position, Time.deltaTime * speedAdjust);
transitionCamera.transform.position = positionCurrent.transform.position;
}
Would someone be willing to explain to me what I am doing wrong? Thanks!
Answer by TheHoboCoder · Jan 14, 2013 at 03:56 PM
Try calling reorient from Update
Didn't realise it was going to be such a simple solution hah! Thanks! One more question If you wouldn't $$anonymous$$d, how would I make the function be reversible, change it back after I get to cam2's position?
function ReOrient (reverse : boolean){
if(reverse) {
positionCurrent.transform.position = Vector3.Lerp(posCam1.transform.position, posCam2.transform.position, Time.deltaTime * speedAdjust);
}
else {
positionCurrent.transform.position = Vector3.Lerp(posCam2.transform.position, posCam1.transform.position, Time.deltaTime * speedAdjust);
}
transitionCamera.transform.position = positionCurrent.transform.position;
}
So if you want to reverse it, just call:
function Update () {
ReOrient(true);
}
For normal behavior call:
function Update () {
ReOrient(false);
}
For some reason it only works in forward but not in reverse, I think it may be because of this weird thing thats happening with cam1. When I play forward, the transitional camera moves along the correct path, but for some reason I cant figure out, cam1 follows the transitional camera.
They aren't parented, and I have no other scripts than this acting on the cameras. When I try the reverse of this function, it goes to the starting location, but because cam1 follows it, it has nowhere to transition to, so it just stops.
Do you know what could be causing this?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Problems with Lerp. 1 Answer
How to smooth my camera (Vector3.Lerp) 0 Answers
Smooth Camera/Object Movement 1 Answer
How you change another script value smoothly on trigger 0 Answers