wood burning stoves
The moose likes Game Development and the fly likes Vector Collision Detection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Game Development
Bookmark "Vector Collision Detection" Watch "Vector Collision Detection" New topic
Author

Vector Collision Detection

Wes McClintock
Greenhorn

Joined: Jul 19, 2011
Posts: 25
So I've been working on a tile based platformer (actually a Jump n Bumb rip). I have vectors, delta time, and all that stuff working, the only problem is I'm not sure how to do the collision. All tiles have a solid boolean value, and I can check if the player is actually IN the tile just fine. The problem is I don't know how to make the player stop just on top of the terrain, or stop them from moving straight into/through the terrain when it lags. I can do this fine when its just 4 direction movement, but the vectors are just messing all my attempts up.

Thanks in advance, you guys are always so helpful.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3986
    
  18

When the program lags, your position may skip well beyond the point where a collision could have taken place. So what you need to do is think of the path you travel between two loop iterations as a line segment and then see if that line segment intersects with any surface (which are also line segments). For line segments within a two dimensional plane this means solving a relatively simple equation.

When your path intersects with a surface, you can then relocate your object to the intersection point, instead of to the end of its path.

Here's an article that details how to solve the equation for two lines within a two dimensional plane: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Wes McClintock
Greenhorn

Joined: Jul 19, 2011
Posts: 25
Stephan van Hulst wrote:When the program lags, your position may skip well beyond the point where a collision could have taken place. So what you need to do is think of the path you travel between two loop iterations as a line segment and then see if that line segment intersects with any surface (which are also line segments). For line segments within a two dimensional plane this means solving a relatively simple equation.

When your path intersects with a surface, you can then relocate your object to the intersection point, instead of to the end of its path.

Here's an article that details how to solve the equation for two lines within a two dimensional plane: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/


Thanks! I think I can get it working now.
 
Have you checked out Aspose?
 
subject: Vector Collision Detection
 
It's not a secret anymore!