Different behavior with the same code; I am having trouble finding the issue

Hey what’s up!

I am trying to do some fancy Camera work with scripts, and I am running into an issue where the same code is working a lot of the time, but is weirdly producing an inconsistent behavior, inconsistently…

Basically, I have a Camera that can be Panned, Zoomed, and Rotated by the player (this does not use Cinemachine). The Camera ‘looks at’ the the GameObject clicked by the player, and the player can then Pan the Camera after… Next, the player can do the rotation around the selection, and the Camera will ‘lerp’ back to the selection as a focal point, while still rotating as this occurs…

Or, most of the time this happens. However, there is a weird artifact where every so often the lerp will start way out of position and create a “jitter” for one instant, before reverting back to the proper lerping course…

This process is spread over multiple scripts, so I’m not sure how to efficiently share it all in this thread. Basically, it seems like the starting lerp position is set way out of position randomly for some reason. That, or there is something messed up in the script execution order.

Is it possible for a Lerp to accidentally have a negative iterator value? It that isn’t it, the best idea I have is that the data reference is getting corrupted for one frame for some reason.

Not sure what else to do here. Let me know how I can share more information to sort this out.

Here is a video clip of the above behavior in a LinkedIn post - https://www.linkedin.com/posts/benjamin-apprill-1734b8a6_hello-all-i-am-running-into-a-bizarre-bug-activity-7010119914657107968-umLh?utm_source=share&utm_medium=member_desktop

Alright! I fixed this issue.

I had the final position of the previous lerp still set within the Lerp variable. This should not have been a problem, but it turns out that script execution order was randomly executing the rotation code before the lerp code updated the variable for the new lerp.

This is why the code was basically correct, but it was updating out-of-order, causing the bug. I simply reverted the variable to ‘default’ in the lerp code upon lerp completion, and added a check in the rotation code to see if the variable was default or not…

This fixed the random cases where the rotation code updated before the lerp code by not updating the camera position until the lerp variable has the correct starting position :smile:

1 Like

Well done

i was going to suggest lerp itself may have been getting confused. But you resolved :]