markcwm / openb3d.mod

OpenB3D BlitzMax wrapper, see openb3d.docs for examples
18 stars 7 forks source link

EntityCollided() Breaks if multiple entities with the same type set, which collide more than 1 type. #11

Closed Kippykip closed 5 years ago

Kippykip commented 5 years ago

Very oddly specific bug, it's the best way I could think of titling it. From what I understand if you have multiple entities with the same type (such as a bullet) set on the entities and use Collisions() on them with two other types (such as the map, and some enemies). Whenever there are some bullets not hitting anything, the other bullets that are colliding won't be able to be tested with EntityCollided or CountCollisions().

I made an example attached below: collisionbug.zip

I also made a syntaxbomb thread on it, which contains a YouTube video demonstrating the bug

markcwm commented 5 years ago

Yes, it's my oddity, the last fix to collisions was to stop the collision list being erased which broke multiple collisions, my solution was a hack using a counter but it was badly thought out and created this bug, now it checks no_collisions which seems to be the correct way to do it.

Kippykip commented 5 years ago

Can confirm it's now fixed!

Kippykip commented 5 years ago

Actually, it looks like it's broken something else in the process. I noticed that the player in my gamebase now seems to always think it's colliding on the ground? If I play around with my noclip bind (which uses ResetEntity) I can make the player realise it's not on the ground again. But once the player touches the ground after that, the problem comes back.

Looking at CountCollisions(Player), it continuously increases when touching the ground (say from 1 to 140 for example), but when I float in the air, the number stays the same as what it last was (say 140). When toggling noclip which uses ResetEntity, the CountCollisions(Player) starts counting from 1 again.

I'll have to see if I can make an example.

Kippykip commented 5 years ago

I looked into minib3d source since collisions worked perfectly on there. From what I understand, minib3d's code cleared all the collisions first and then started counting them up. When looking at the original OpenB3D library source, it seems to clear the collisions as it loops through each type which is probably why it's all getting messed up.

I made a workaround which involves looping through the Entity Types twice with two different functions. Clearing all collisions first, then counting through them all. https://github.com/Kippykip/openb3dmax.mod/commit/40ec71fd3063c9bbe5477fb8dd70e68142cbb4be

There's probably a much better way of doing it, but I'm no expert when it comes to C++ but I've tested this in my project and from what I can tell, all collisions are working flawlessly.

markcwm commented 5 years ago

Yes my bad, I didn't check my fix against anything else, anyway your fix seems to do the job so thanks for that and nice work! Testing blitz3d/Collisions showed up the ground no_collisions always increasing bug. Yes the collision loop is a bit different in Openb3d so I think you probably have to do what you did and just reset everything first.

Kippykip commented 5 years ago

Haha no problem! Happy to contribute!