- Home /
Easy transition between multiple views?
Hi! I'm trying to set up a 3D model with about 25 different views. Ideally, a user would be able to just tap a key on the keyboard for each view and transition smoothly from their current camera view to this new one (similar to how the Google Sketchup 'Scenes' work). Is this possible?
And if so, would it be better to have a single camera somehow animating to each of the 25 views, or is it possible to have each camera separate and transition smoothly between any two?
Appreciate the help!
I think that the easiest way to set that up would be to animate the camera itself then calling those animations using Animation.CrossFade
Here's a tutorial on how to create animations in Unity in case you need it: http://www.youtube.com/watch?v=$$anonymous$$WC6Pw63BAY
Answer by Spinnernicholas · Dec 02, 2013 at 02:56 AM
Create and position cameras for all of the views.
Delete the cameras and other components, leaving just the GameObjects.
You now have the positions and rotations of all of the views.
Create a script to lerp between them:
Now, this is a very simple script and needs a lot of work. But it should get you started.
Using System.Collections.Generic;
class CameraViews : MonoBehavior
{
public List<Transform> views;
public float transitionTime;
int float startTime = 0;
int current = 0;
Awake()
{
//Init to first view
transform.position = views[0].position;
transform.rotation = views[0].rotation;
}
Update()
{
if(startTime != 0)
{
transform.position = Vector3.Lerp(views[current-1].position, views[current].position, (Time.time - startTime)/transistionTime);
transform.rotation = Vector3.Lerp(views[current-1].rotation, views[current].rotation, (Time.time - startTime)/transistionTime);
if((Time.time - startTime)/transistionTime > 1)
{
startTime = 0;
}
}
}
nextView()
{
current++;
startTime = Time.time;
}
}
You could also reconfigure this to transition between any two views.
Thanks guys. I should have mentioned I'm very new to coding with Unity, so I would love a little more guidance (I'm also much more familiar with Javascript than C# but I'll take what I can get).
As I understand, the script above is creating a list of views. In my case, it would be view[0] through view[25], right? What I don't see in the script is where I'd actually be plugging in the transform coordinates for each view[]. For example, in the above code, where would I put the coordinate -25,32,45 for the first view? Thanks.
Also, all views are pointing at the same target, so I should be able to do all this sans transform.rotation code, right? I just have a simple LookAtTarget script.
Thanks so much!
The goal is to use the editor as much as possible, so we avoid hard coding data, like coordinates.
For this script, you would have several GameObjects that each represent a camera position and rotation.
In the editor, you will add each of those GameObject's Transforms into the View list.
This script will start a transition from it's current view to the nextview in the list whenever nextView() is called.
You have modify this code to prevent it from trying to access outside the bounds of the list and to prevent nextView() from being called while a transition is already in process.