Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411518 Posts in 69377 Topics- by 58431 Members - Latest Member: Bohdan_Zoshchenko

April 28, 2024, 02:36:43 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Move to contact problem?
Pages: 1 [2]
Print
Author Topic: Move to contact problem?  (Read 3616 times)
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #20 on: December 22, 2009, 02:18:44 PM »

Alright, I put in a method where you check every pixel on the way to the collision.
It works... but now if you move diagonally against the wall, the object clips 1 pixel over the walls corners.  Shrug



Hotdamn.
Logged
Tycho Brahe
Level 10
*****

λx.x


View Profile
« Reply #21 on: December 22, 2009, 03:25:33 PM »

If you're moving fast (more than a few pixels in one update), just subdivide the move into several steps.  Even pixel-sized steps if you want.
It might just be eaisest to create a shape linking the start position to the end position and then hit-test against that

eg, instead of this, where you hit-test in all of the black boxes (and the light grey one hits):
Code:
              
               ▓▓▓▓▓▓
▓▓▓ ---> ▓▓▓ ->▓▒▒▒▓▓-> ▓▓▓
▓▓▓      ▓▓▓   ▓▒▒▒▓▓   ▓▓▓
               ▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓


and then resolving it...

Code:
                ▓▓▓▓▓▓
            ▒▒▒▓▓▓▓▓▓
            ▒▒▒▓▓▓▓▓▓
               ▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

you do this, where you test the light grey areas:
Code:
                ▓▓▓▓▓▓
▓▓▓░░░░░░░░░░░░▓▓▓▓▓▓░░░░░░▓▓▓
▓▓▓░░░░░░░░░░░░▓▓▓▓▓▓░░░░░░▓▓▓
               ▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

and then resolve it by figuring out the last position at which they did not overlap (shown here in medium grey):

Code:
                ▓▓▓▓▓▓
▓▓▓░░░░░░░░░▒▒▒▓▓▓▓▓▓░░░░░░▓▓▓
▓▓▓░░░░░░░░░▒▒▒▓▓▓▓▓▓░░░░░░▓▓▓
               ▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓

This way, you only do one larger ABBA (or box) test, instead of a number of smaller ones. Even if the player is moving diagonally it would just be a matter of doing a few line/line intersection tests instead of a box. It *should* be quicker, however I'm no expert on collision detection/resolution and I haven't tested it so I might be wrong.
« Last Edit: December 22, 2009, 03:53:21 PM by 14113 » Logged
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #22 on: December 22, 2009, 03:37:24 PM »

Update:
I already solved that motherfucking bug.   Hand Shake LeftEvil:handshakeR:

It turns out I was iterating one too many times in my contact loop.  So when I'd test along the y axis, the objects x position would be 1 off from where it should be, thus fouling the y-axis test.
Logged
Epitaph64
Level 1
*



View Profile WWW
« Reply #23 on: December 23, 2009, 03:59:37 PM »

Another way to do quick testing, is to find the ratio between X and Y speed between start of frame, and projected end of frame (if there were no collisions). So, say that you are moving 3 times faster X than Y. Then you check the object moving to the left for the amount of times that the X is a multiple of Y, and if it's colliding, return true (for collision). After that do the same for Y. If Y is greater, i.e. the object is falling at a speed of 4 and moving to the left at a speed of 1, reverse the order that you check them in.
Logged

Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic