简体   繁体   中英

Frame object during position lerp

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 :( 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?

The Quaternion.LookRotation() method should be enought:

    public GameObject TargetObject;
    public GameObject CameraObject;

    void Update () {
        CameraObject.transform.rotation = Quaternion.LookRotation(TargetObject.transform.position- CameraObject.transform.position );

    }

I hope this can help you.

在此处输入图片说明

both angles are equal... if you can calculate the world coordinates of the moving object (based on the view port coordinates) you can also can calculate the world coordinates of the target.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM