Moving The Camera

I’ve looked at every example I can find and still don’t get it. I have two default camera views that I want to switch between when the user clicks a button. Click once – go to view 1, click again – go to view 2, click again – go to view 1, and so on. A simple toggle that smoothly moves the camera to one of two positions. I’ve ended up with a pretty simple LateUpdate function that just Slerp’s the position and rotation, much like the examples I’ve seen.

I’ve been able to get the camera to move smoothly the first time, but after that the camera just jumps to the end position. For each position I have a start position and rotation, and an end position/rotation. Depending on the state of the button, the start and end swap.

Some things I don’t understand:

How do you know when the camera reaches its end position? I tried comparing the camera’s current position/rotation with the end position/rotation, but that’s never true.

How do you disable the LateUpdate function after the camera has reached its end position? I tried GetComponent(“CameraControl”).enabled = false (and several other variations), but can’t get it to compile. I can’t get it to stop calling the LateUpdate function when the camera doesn’t need to move.

I don’t understand how the time parameter works. All the examples use deltaTime, but if I use that the camera just shakes and never goes anywhere. The only time parameter I can get to work is (Time.time * someValue).

If you are using Indie version some of that wont work.
Also I use Time.fixedTime a lot. Unity is a bit of a pain with calculating real time you need to count it yourself really.

Can you show us what code you have so far with your script?

There’s nothing described by the OP that would need Pro. Also it’s usually a bad idea to use FixedUpdate for anything except physics; calculating time isn’t a pain that I know of.

Anyway, use coroutines, something along these lines.

–Eric

I cannot get the enable/disable for scripts to work in Unity Indie 2.6 either.

And Time takes a few extra lines of code to accurately calculate in Unity, if you use other software to track it unity is always out by small portions of a second each second and is not consistently out.
You can count accurately in increments, but by milliseconds is damn hard. :stuck_out_tongue:

At least I have not found one given solution on the site or forums that actually works accurately when tested.

It works fine; “this.enabled = false;” for example…nothing to do with Indie/Pro. Anything that’s Pro-only is listed here. As far as time goes, there’s Time.time and Time.realtimeSinceStartup among other things.

–Eric