Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 1921 times)
0 Members and 1 Guest are viewing this topic.
Offline Murdockian

Senior Newbie




Java games rock!


« Posted 2003-10-21 13: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! Wink

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

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #1 - Posted 2003-10-22 02: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 05: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
/Markus
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2003-10-22 14: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.

xsi3rr4x (62 views)
2014-04-15 18:08:23

BurntPizza (60 views)
2014-04-15 03:46:01

UprightPath (73 views)
2014-04-14 17:39:50

UprightPath (56 views)
2014-04-14 17:35:47

Porlus (73 views)
2014-04-14 15:48:38

tom_mai78101 (99 views)
2014-04-10 04:04:31

BurntPizza (159 views)
2014-04-08 23:06:04

tom_mai78101 (254 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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
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!