Help needed :( funky maths problem

I’ve got a camera which is moving to an end position. For the entire duration of the movement, I want to frame an object so the motion looks appealing to the player. The framing of the object does not necessarily stay the same throughout the entire motion ( I want to be able to lerp the viewport position of the object during the lerp )

  • I have the starting position and rotation of the camera
  • I have the start viewport position of the object relative to the camera
  • I have the end viewport position of the object relative to the camera
  • my camera is orthographic, so I don’t have to worry about frustrum sizes / field of views
  • Just a direct lerp between start and an end rotation is not a good solution, as it loses the framing that I’m looking for (tried)

For each update in my lerp:

[1] - I tween between the start and end position of the camera
[2] - I tween a viewport position that I want to use between start and end viewport position
[3] - I need to calculate the new rotation required to keep the object in my new viewport position calculated in [2]
[4] - I update the rotation and continue the lerp

However, I’m a bit stumped with the calculation in 3 :frowning: I’ve tried a few variations to try and calculate this, but I can’t seem to find a good solution. Does anyone know how to calculate this? Am I approaching this from the correct angle?

What’s wrong with transform.LookAt?
It sounds like an animation COULD be useful here

The problem with lookat is that I am not actually looking at that specific object. It is somewhere in my viewport space, and I want to move it from 1 point in my viewport space to another point in the viewport space during the position motion itself.

Let’s say at the start of the motion it’s on the right hand side of my viewport. I want to end up with it being framed on the left hand side of my viewport, but I want to do it over the position lerp time. This way, the user always has their eye focussed on the object in the scene, and it is positioning itself in an easy to follow manner.

The problem with an animation is; I don’t always start at the same point. The level is procedurally generated, so I can finish anywhere really. As soon as the end of the game is triggered, I want to do a specific framing of objects to give a nice victory sequence. But the way I currently have it it’s a bit nauseating because the rotation is flying all over the place before getting to its final rotation.

You know the start and end framing of the object? I take that to mean that you know what viewport coordinates you want the object to have at the start and the end of the movement?

What you need is to lerp the wanted viewport coordinates. Then you need some code that given the camera’s position, the object you’re looking at’s position and some viewport coordinates, gives you the correct camera rotation.

Does that make sense? Can you do that?

That’s exactly what I want to do, but it’s the calculation of the camera rotation that is causing me to be a bit stuck :(. Any tips or broad lines as to how I can achieve that rotation?

Because It’s an orthographic camera, I don’t have to worry about how far away the object is, but I still need to know how much 1 unit of rotation relates to the viewport unit changes ( I’m saying this very badly, but I know I need to know the relation between the 2 )