Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D Collision detection / reaction  (Read 2944 times)
0 Members and 1 Guest are viewing this topic.
Offline Murdockian

Senior Newbie

Java games rock!

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


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! Wink

This is where I hope that you guys come in and make my day a little brighter - Thanx!
Offline 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?
Offline 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 Wink 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 Wink 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 Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2003-10-22 12:17:46 »

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  

EgonOlsen (79 views)
2018-06-10 19:43:48

EgonOlsen (59 views)
2018-06-10 19:43:44

EgonOlsen (78 views)
2018-06-10 19:43:20

DesertCoockie (261 views)
2018-05-13 18:23:11

nelsongames (159 views)
2018-04-24 18:15:36

nelsongames (158 views)
2018-04-24 18:14:32

ivj94 (901 views)
2018-03-24 14:47:39

ivj94 (162 views)
2018-03-24 14:46:31

ivj94 (813 views)
2018-03-24 14:43:53

Solater (177 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!