Simple way to pan from one object to another?

I found the LookAt() function but it “jerks” the camera into position. Is there a simple way to have the camera smoothly look from one object to another or does someone have a script they can share that does this?

Thanks!

transform.rotation = Quaternion.Slerp(transform.rotation, gnom_rotation, rotation_speed * Time.deltaTime);

What are you using for gnom_rotation? Can you explain where you put the start and stop target in that formula?

Not sure what he ment by gnom there but that is where the target rotation goes.

Here’s how it goes -

Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed);

Search for Slerp in the scripting reference.

:smile:
Oops, that was some code copy\pasted from my hobby project. “Gnom” is a hero’s name.

Gotcha, I found the info about Slerp.

Here’s a question about it now. How do I find the end-rotation in order to “look at” the object I want to? I have the LookAt() function but don’t see a way to just retrieve the look at angle without actually looking.

You can use Quaternion.LookRotation:

Note that it works slightly different from transform.LookAt, you need to provide the look vector instead of the target position:

newLookAt = Quaternion.LookAt(newTarget.position - camera.position);

Great, thank you!

I may have spoken too soon. There is no Quanterion.LookAt() function in Unity.

So, here’s my question, how do I get the Quanterion for the current rotation and also the Quanterion for the rotation I want to use as the target?

I have the camera to start with and I know the position of the item I want it to pan to look at. Can someone help me with the code needed to pan from the current state to the state desired?

var camCurPos : Vector3 = camera.transform.position;
var camCurRot : Quanterion = camera.transform.rotation;
var camTargetPos : Vector3 = targetobject.transform.position;
var camTargetRot : Quanterion = targetobject.transform.rotation;

What do I need to write code wise given the above data to arrive at the camera rotation needed on the next frame and pan towards the target over time?

Thanks!

Well, I cheated and added a spotlight to my scene and put it exactly where the camera is but turned its Intensity to 0. I have it call LookAt() to get the target rotation and then call the Quanterion.Slerp() to slowly transition the camera from its current rotation to the one the spotlight is pointing at.

It works but I would like to know how to get the LookAt() rotation without having to use this hack. Does anyone have the math to calculate the LookAt() value without actually having to perform the LookAt() function?

My post was correct. The Quaternion function is not called LookAt but LookRotation.