- Home /
Smooth transition of camera targets
Hi there!
So, I'm make a Space RTS (more like a Space Combat Simulator) with diferent type of fighting objects (Ships, Fighters, Stations, etc.) and the player will have the need of switching the view between them, which may be thousands of meters appart from each other. As such making a sudden transition, would be visually unpleasant.
I'm already using the Mouse Orbit script from the standard assets, adapted to allow Zooming In and Out of the target (using the Mouse ScrollWheel Input).
So, how could I make a "yielded", lerp transition, keeping stuff like camera distance and orientation identical?
Thanks in advance.
João Borrego
if you look at the SmoothFollow script youll see rotation damping and height damping on the camera, forcing a smoothed "slide to position." You could try to copy that idea and tweak it to fit how you want?
Hmm I'll check it out... I'll tell you later out it worked out...
Answer by ScroodgeM · Aug 13, 2012 at 06:19 PM
one of thousands of ways to achieve that:
all below is to improve camera control script
declare a value that will store a object (X) or position that camera should observe from (station, ship, etc - transform is better cause you will follow the object on it's movings)
in Update() method, compare distance from camera to (X) and smooth move camera to this position (see below)
depends on previous check of movement needed and your gameplay, apply or not other camera controls (want you to control camera while it moving?)
some good methods to move camera smoothly:
move it by 0.1-0.5 of distance per second. this will move camera fast at start and slow on close to finish
move camera by 0.1-1 of distance stored before moving starts. this will move camera linear
move camera using AnimationCurve - so you can customize camera moves as you wish. for example, like elevators - slow accelerating and break, but fast movement between it
Answer by Dragonlance · Aug 13, 2012 at 06:58 PM
Well in my space game I give the object a camera position empty game object and a lookat empty game object (yould be in front or above of it)
Then I let this run on the camera: bool stateReached = false; Transform currentLookAt; Transform currentTargetTransform; ...
// Perform Rotation
Quaternion rotation = Quaternion.LookRotation (currentLookAt.position - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime);
// Transform
if (!stateReached) {
// Transform Position
transform.position = Vector3.Lerp (
transform.position,
currentTargetTransform.position,
Time.deltaTime);
if (Vector3.Distance (transform.position, currentTargetTransform.position) < 0.1f) {
stateReached = true;
}
}
I only need to reassign the currentLookAt and currentTargetTransform and the cammara starts flying there. If it is arrived and the target moves is smoothely follows. You could even temporary assign an enemy as currentLookAt (to follow your current traget or something)
This is just a snipped, but it should work out of the box. Maybe you need to add checking for null pointers etc. I stripped that out.
Of yourse you can do this yielded too with while(!stateReached) but the cammera will stop acting smooth after arriving.
Your answer
Follow this Question
Related Questions
Mouse Orbit snapping issues 0 Answers
camera orbit on mouse drag 2 Answers
Camera Orbit on Left Click problem 0 Answers
Move Camera According to Mouse Movement While Button is Pressed 1 Answer
Need help with a mouse orbit script 1 Answer