#Collision of fish in a simulated fish tank leads to them disappearing

7 messages · Page 1 of 1 (latest)

analog yew
#

This is a Fish Tank, where certain variants of fish can "swim" in. They move horizontally and vertically (the vertical movement is random). But one aspect is not covered yet. When two fish collide one fish just disappears and never gets shown again. I would like to cover this case in the moveFish method or in a separate method, where the larger fish covers up the smaller one until they have different positions again.

junior elmBOT
#

This post has been reserved for your question.

Hey @analog yew! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

analog yew
#

Collision of fish in a simulated fish tank leads to them disappearing

prime merlin
#

Perhaps this will be of use to you or not, but it doesn't hurt to suggest;

When your objects collide, and depending on how you are handling the physics of this collusion, there is a chance that one fish may end up having the same exact position as another one. This will result in only one of them being drawn due to the nature of discreete screen coordinates in a 2d array to print to the screen

#

I would start by making sure that either thr collisions don't result in fish having the same coordinate, or you can work around this issue by creating a section in your simulation loop to check for overlapping fish, and push them away from each other