Timeline for 2D Collision Detection XNA C#
Current License: CC BY-SA 3.0
14 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 5, 2015 at 7:33 | comment | added | Bruno | I noticed that the cases are Vertical if--else-if and Horizontal if--else if. When I change else to just if, one of the conditions gets fixed and the other broken. Anyway, that's irrelevant now. 2 rectangles for the Player - one for vertical check and one for horizontal? Hmm... wouldn't that actually result in what we have now - with 2 bound cases being true? And what exactly do you mean by cross rectangles? If it's about having a thinner rectY, wouldn't it be better to just pick a middle point from bottom/top, etc... Wait, no. I did try that. | |
Aug 5, 2015 at 6:54 | comment | added | Andrew Wilson | @Bruno the left push and right push is because two of those bound cases can be true in a collision. The horizontal case can execute with the vertical one and since the vertical case is last if pushes it vertically. You could compare the depth's width and height but you will run into this sticky corner problem. I suggest modeling the player with a cross and using the vertical rectangle for y axis collisions and horizontal rectangle for x axis collisions. | |
Aug 5, 2015 at 6:08 | history | edited | Andrew Wilson | CC BY-SA 3.0 |
added 80 characters in body
|
Aug 4, 2015 at 22:25 | comment | added | Bruno | Thanks for the idea. I'm going for the bound checking. This type of collision checking is better than what I had. I rewrote the whole ApplyCollision() method. However, the conflict between conditions is still present. I updated my question in the topmost comment. Read after the EDIT part. P.S. Sorry if I'm getting annoying with asking for help on each step of the way. I'm a slow learner and this isn't my first time struggling with physics implementation. | |
Aug 4, 2015 at 8:42 | comment | added | Andrew Wilson | @Bruno and if don't want to do bound checking you could use the minkowski sum. gamedev.stackexchange.com/questions/29786/… | |
Aug 4, 2015 at 8:38 | history | edited | Andrew Wilson | CC BY-SA 3.0 |
added 80 characters in body
|
Aug 4, 2015 at 8:31 | comment | added | Andrew Wilson | @Burno I edited something in the answer about bounds checking. | |
Aug 4, 2015 at 8:30 | history | edited | Andrew Wilson | CC BY-SA 3.0 |
added 634 characters in body
|
Aug 3, 2015 at 14:47 | comment | added | Bruno |
Ahh, but not that easy. Center.X(or Y) messes with the horizontal collision on the Platform sides. Whatever condition I think of, overlaps with the Vertical Checks. Can't find a way to have both Vertical and Horizontal collision at the same time. *sigh*
|
|
Aug 3, 2015 at 11:22 | comment | added | Bruno | Just before you wrote this comment, I found where my error was. PlayerIsOnPlatform() and PlayerHitsPlatformBottom() were stepping into each other. If playerBottom >= platformTop >>> put player on top. If playerTop <= platformBottom >>> prevent player from passing through platformBottom. In the second condition playerBottom is still greater than platformTop. Thanks for bringing the Center property to my attention. I never thought about it. It was a crucial part in fixing this. All that's left is to finish the side collision. I'll need to refine my conditions even more. Thanks! | |
Aug 3, 2015 at 9:03 | comment | added | Andrew Wilson | @Bruno using my previous suggestion you can just throw and extra if statement saying if(player.Center.Y > platform.Center.Y) { player is above } else { below } if he is above then subtract the depth and if he is below add the depth. (IE: Intersection.Height is the depth. intersection is the purple rectangle) I suppose you could also use the velocity of the player before collision. to tell whether he was below or above. If(collision) { if(v is positive) { moving upwards so he is below} else { moving downwards so he is above. } } | |
Aug 2, 2015 at 8:37 | comment | added | Bruno | Thanks for the suggestion! I do use rectangles and the intersection method. And I got things working. Shiro helped me see what I got wrong. But now I have another problem. I edited the top comment. Care to check it out? | |
Aug 2, 2015 at 2:30 | history | edited | Andrew Wilson | CC BY-SA 3.0 |
added 34 characters in body
|
Aug 2, 2015 at 2:25 | history | answered | Andrew Wilson | CC BY-SA 3.0 |