Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (522) Games in Android Showcase (127) games submitted by our members Games in WIP (590) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D Collision detection / reaction  (Read 2026 times) 0 Members and 1 Guest are viewing this topic.
Murdockian

Senior Newbie

Java games rock!

 « Posted 2003-10-21 11:34:37 »

So,

I'm implementing collision detection to my 2D game engine and I have some problems as of how to get going.

All my game objects are polygons that I've tweeked / implemented myself so the speed is not any problems. However, I wonder how I should detect the collisions...

At the moment I cmp polygon segments with each other i a nice (?) N2 mannor and generate a list of normals that I've intersected. The next step is the tricky part though since I don't know how to react.

I mean, imagine a box approaching a different box horizontally until you detect collision. The collision I've detected only contain two normals - the top / bottom surfaces of the testpolygon.

I've tried to simply calculate the penetration depth of the collision and seperate the objects from each other according the velocity of the gameobject that collided, but there's a major bug to that:

What if my gameobject is a person walking on a ground polygon and the person is affected by gravity - Then I detect collisions constantly (to keep the person from falloing though the floor) and when the person tries to move in any direction, he's more or less stuck!

I feel that I have to calculate scalar-products with the normals of the surfaces that I've collided with, but then I have to calculate differently since I havn't detected the surface directed towards the approaching box in the above example... Gaah!

This is where I hope that you guys come in and make my day a little brighter - Thanx!
/Markus
nonnus29

Senior Devvie

Giving Java a second chance after ludumdare fiasco

 « Reply #1 - Posted 2003-10-22 00:43:29 »

Are you using bounding rectangles or spheres before doing your polygon test?  Sorry but its not obvious from your post.

I had the same problem though not with polygons in 2d (well, bounding rectangles count I guess but I used a simple overlap test);  You have to switch your approach a little.  Don't check for falling if the character is not falling.  So first check if there is contact with the ground polygon; if not then you know your falling so continue to check and add gravity etc... till you do reach the ground.  Its kind of hard to put into words.

Err, so don't inc delta y unless there is no contact with a ground polygon?
Murdockian

Senior Newbie

Java games rock!

 « Reply #2 - Posted 2003-10-22 03:38:05 »

Yes, I do a bounds-test before going into the polygon cmp algorithm I was in a hurry when I wrote the post - My bad...

I feel a bit doubtsome to the "if contact, then don't"-sollution since that isn't as "general" as I want it to be. What if I jump towards a wall? Then I should stop moving horizontally, but still add gravity to make the caracter fall down... In my engine, the gravity is custom to the game you implement, thus you can have horizontal gravity in both directions AND/OR vertical gravity...

I don't want to think about the number of "special cases" that I would have to define in order to make it work And if I made it work, I'd probably find a case that I didn't cover sooner or later...

The only real general sollution must (should?) somehow involve the normals of the surfaces that I detect collision with... I just don't see how at the moment  :-/

Perhaps I could try to combine the "if contact, then don't" concept and just ignore all incrementations of the object's velocity that has a composant in the same direction as the collisoni sureface... that would allow forces to work on the objects without further trying to go "into" the surface that I've detected collision with...?

In need of more input
/Markus
tom
 « Reply #3 - Posted 2003-10-22 12:17:46 »

Quote
What if I jump towards a wall? Then I should stop moving horizontally, but still add gravity to make the caracter fall down...

Get a line representing your movement during a frame. If there is a collision find the colliding point and the end point projected on to the colliding plane. Use the colliding point and projected point as a new line and check for collision recursivly until there is no collision.

Some like to do the gravity movement in a seperate step. That way you can possibly simplify you collision response.

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 trollwarrior1 (29 views) 2014-11-22 12:13:56 xFryIx (71 views) 2014-11-13 12:34:49 digdugdiggy (50 views) 2014-11-12 21:11:50 digdugdiggy (44 views) 2014-11-12 21:10:15 digdugdiggy (38 views) 2014-11-12 21:09:33 kovacsa (62 views) 2014-11-07 19:57:14 TehJavaDev (67 views) 2014-11-03 22:04:50 BurntPizza (64 views) 2014-11-03 18:54:52 moogie (80 views) 2014-11-03 06:22:04 CopyableCougar4 (80 views) 2014-11-01 23:36:41
 theagentd 28x basil_ 27x HeroesGraveDev 23x BurntPizza 21x Riven 19x Spasi 18x princec 17x KevinWorkman 13x SHC 11x kpars 11x Grunnt 10x gouessej 10x Nate 9x Longarmx 9x CopyableCougar4 8x LiquidNitrogen 8x
 Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50List of Learning Resources2014-07-31 16:29:50List of Learning Resources2014-07-31 16:26:06
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org