Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / The last step for a nice 2D collision

Author
Message
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 6th Feb 2011 22:49
I have written my own pixel perfect 2d collision detection after finding out DBP is so professional it needs an additional $32 to be able to detect even rotated box sprite collision properly.

Now i'm real happy it all works awesome and fast, but bounced into a new problem, which involves putting the object away from the wall when an impact occurs.

What i do, and what i think is the average solution, is to put the collided object back to its last position when a collision was detected. This is nice, and works 100% perfectly without rotation. When the object starts rotating, rarely, but it sometimes happens, that the earlier position points slighty towards the wall, what we are trying to bounce off here.

The "get out from the wall" code of mine is a little 'repeat/until Collision=0' part (because usually, also because of rotating, putting one step back is never enough, it needs to repeat stepping back for at least 2 times...), so if the above phenomenon happens (previous position points towards the whole), the object starts a milisecond travel through the wall, and mostly ends up on the other side of the stage, right on the other side of the actual wall.

Is there any snippet, formula whatever, which produces a nice stop at walls, even if the object rotates?
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 6th Feb 2011 23:44
'Kay, well the usual thing happened, i opened a thread, and something told me the answer after pushing enter. A guardian angel, whatever who knows. Ah these threads are not only for individuals to get to know their answers, if somebody has the same problem, he or she will some time find this and maybe try learn. Or not..

It's still if i try hard likes to get stuck, but i feel it's only from a little fine adjusting from perfect.

What i basically do, is expanding the idea of "putting the object back to its previous position", by also concentrating on its angle, AND storing a short history of its previous states, and not only the very last one before the collision. So if the very last is still colliding, i just rewind it back one more frame. Repeat this until the object is finally out of the wall. Then the bounce-off function starts, but that wasn't part of the problem.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 7th Feb 2011 00:18
Ideally you want to detect if the object would collide with another before it happens, not after.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 7th Feb 2011 15:27
Ah, nice tip pal thanks!

Heh, how obvious...

Login to post a reply

Server time is: 2026-07-15 22:38:55
Your offset time is: 2026-07-15 22:38:55