You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a browser tab is left inactive, p5 does not update. When the user switches back to the tab, p5 will update but with a large deltaTime. To prevent the fish from going flying, I have a check in the fish's movement which sets deltaTime to a small value if it is detected to be very large. This means boiding fish will boid as usual, however, it presents a problem for fish that were in the process of moving to a target.
To move a fish to a target in a given time frame, I am currently calculating the velocity required to move it within that time, setting that velocity, and then setting it back to boiding/idling after the time has passed. This depends on the fish moving the exact amount of time with that velocity. This gets messed up when the tab is inactive.
I can't simply move the fish for the actual elapsed deltaTime as this may be longer than the amount of time it was supposed to traverse the time. The best solution is probably to track the target point "moveto", and simply move the fish to that point instantaneously if a large deltaTime was detected. This feels bad because it is extra state to track and update, but it's probably the best way.
The text was updated successfully, but these errors were encountered:
When a browser tab is left inactive, p5 does not update. When the user switches back to the tab, p5 will update but with a large
deltaTime
. To prevent the fish from going flying, I have a check in the fish's movement which setsdeltaTime
to a small value if it is detected to be very large. This means boiding fish will boid as usual, however, it presents a problem for fish that were in the process of moving to a target.To move a fish to a target in a given time frame, I am currently calculating the velocity required to move it within that time, setting that velocity, and then setting it back to boiding/idling after the time has passed. This depends on the fish moving the exact amount of time with that velocity. This gets messed up when the tab is inactive.
I can't simply move the fish for the actual elapsed
deltaTime
as this may be longer than the amount of time it was supposed to traverse the time. The best solution is probably to track the target point "moveto", and simply move the fish to that point instantaneously if a largedeltaTime
was detected. This feels bad because it is extra state to track and update, but it's probably the best way.The text was updated successfully, but these errors were encountered: