vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

gjk.lua -> EPA(...): creates an infinite loop #69

Closed yynaa closed 10 months ago

yynaa commented 10 months ago

can be reproduced if a circle is inside a box the local variable diff_dist never goes under 1e-6 (between 1e-5 and 200) abs(diff_dist - last_diff_dist) stays superior to 1e-2

i'm not sure what i can provide to help with this? has this been an issue in the past? thank you!

rzvxa commented 10 months ago

I think it is close to this issue which has been fixed with a hackish commit. #25 https://github.com/vrld/HC/commit/adfe9a9a5dbd2466ff927113e52819543c5f082b

Can you create some minimal setup code so I can test it reliably?

yynaa commented 10 months ago

I think it is close to this issue which has been fixed with a hackish commit. #25 adfe9a9

Can you create some minimal setup code so I can test it reliably?

hello! sorry for the late response. here is a love file that hangs the machine, hopefully for you it does too. i should specify that i use deterministic math functions! they are included in the love file, could they be the cause of this issue? thanks!

HCfreeze.zip

rzvxa commented 10 months ago

Hi, Thanks for providing the sample code.

I've used your main.lua without the Deterministic math functions and it happened to resolve the issue as you can see in this gif. firefox_DUhFLPS8xI I think mixing the 2 math module can't be that good in the long term, Even if we get this issue fixed there might be other problems with this approach. What is your use case? are you using it for multiplayer physics simulation? Deterministic math can be costly so in most games(specially 3D games) math is unreliable and in multiplayer we usually compensate for that with minimal physics in multiplayer. Most physics objects are synced across via their position in the world instead of their inertia.

yynaa commented 10 months ago

Hi, Thanks for providing the sample code.

I've used your main.lua without the Deterministic math functions and it happened to resolve the issue as you can see in this gif. firefox_DUhFLPS8xI firefox_DUhFLPS8xI I think mixing the 2 math module can't be that good in the long term, Even if we get this issue fixed there might be other problems with this approach. What is your use case? are you using it for multiplayer physics simulation? Deterministic math can be costly so in most games(specially 3D games) math is unreliable and in multiplayer we usually compensate for that with minimal physics in multiplayer. Most physics objects are synced across via their position in the world instead of their inertia.

hello, while writing the code i figured it would be that :/ i want my game to be replay/tas friendly, it is a singleplayer game that's why i wanted deterministic math, just to make sure that replays work properly on all machines. perhaps this isn t needed for collision? i m not sure how the algorithm works quite frankly

rzvxa commented 10 months ago

May I know what is the genre of your game? You can get away with using stored positions in the replay file and only play back every object position in the replay mode instead of recalculating its physics behavior. To reduce the replay file size you can only sample positions at a low frame rate for example 10 fps and interpolate between frames to smooth out the replay.

yynaa commented 10 months ago

it is a top down shooter i can "get away" with that solution, however i don t really like it all that much, it breaks some of the stuff i want to eventually implement :/

rzvxa commented 10 months ago

Most games do it in this way, It can make cheating harder too. If you want to fix your mistake in the replay before submitting it you have to change every consequence frame and do it with no jerkiness so nobody finds out. If I'm not mistaken this exact thing resulted in one of the biggest cheaters in Rocket League getting caught, They found some artifacts in his replays, where the ball didn't move with the right speed.