Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fish moving to target end up in wrong positions when browser tab is left inactive #2

Open
cheryllium opened this issue Jan 10, 2024 · 0 comments

Comments

@cheryllium
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant