[SOLVED] Raycast and Position delay

So I’m using the ThirdPersonController from starter assets which has the Cinemachine camera tracking a pivot point on the player Object. Now I want to make the player aim with the camera movement. The problem is the raycast information from the camera position is always a frame behind since the camera is LateUpdate.

I can use the OnCameraUpdated event to get the new position and do the rotation after the camera, however then the animation rig is out of sync and still stuttering.

I’m kind of stuck and reaching out for ideas.

I’m a little confused by this. What rotation are you doing here? Once OnCameraUpdated is called, the camera and player have all been positioned, and you can then safely do a raycast from the camera and have it land correctly.

So input rotates the player. The animation rig is tracking an object that is moved via a raycast from the camera. However since the camera is LateUpdate (rotates with the player), the raycast information the animation rig is using is old.

animation rig tracking object in Update()
Camera information is LateUpdate()

This misalignment is causing the multi-aim constraint to stutter as the raycast is not being updated smoothly. Hopefully, that makes sense.

wealthyshockingcicada

Thanks, I understand.

I can think of these possible solutions:

  • Apply the aiming animation in the OnCameraUpdated callback instead of Update.
  • Set the CMBrain to ManualUpdate mode, and call CMBrain.ManualUpdate() before the aiming animation is applied. This will update the vcam state but not the main camera. You’ll have to use a dummy (disabled) Camera object to do the raycast, using position/lens info extracted from vcam.State.
  • Fake it. Aim towards a fixed point along the player’s +z axis, but make the bullet go to the correct place when it fires.

The ManualUpdate works perfectly thank you, though I didn’t end up using a dummy. I’m calling ManualUpdate in both Update() and LateUpdate(), which I think is worth the extra calculation.

I don’t think you should call ManualUpdate more than once per frame. It’s asking for trouble.