A problem idea for recording the LookAt function

Function introduction:

The game realizes the function of the character looking at the camera, that is, the character turns his head and eyes with the rotation of the camera.

Principle introduction:

Generally, the camera rotates around the character, but when the camera is fixed and the character rotates, the lookAt function will be very strange. When the camera is rotated at a large angle, it is easy to cause the head to twist.

After thinking about it for a while, although turning the camera and changing the role, it seems that there is no difference in relative movement

And because the code lookAt function written is actually the code logic is when the camera rotates, the center of the character's eyes is used as the pivot point, a certain vector, and the movement of the point after the modulo length

When the camera rotation angle exceeds the limit value, the gaze point will quickly interpolate and move to the target point in front of you

Afterwards, when the camera turns to the back at a large angle, it will have no effect on the target point in front of you.

But if the camera does not move and the character moves, then the target point used for interpolation movement is always moving (world coordinates)

Therefore, when the angle between the camera and the positive direction of the character exceeds the limit, the head will be distorted

Thinking about solutions:

When the camera does not move and turns the character, set the target point of the interpolation movement as the sub-object of the character, then the relative motion can be offset, so that after a large angle deviation, the interpolation movement point will stay in the positive direction of the character, and other targets Points are calculated with localposition and localRotation.

Guess you like

Origin blog.csdn.net/l17768346260/article/details/131148701