File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector Collision Detection

 
Wes McClintock
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 4826
34
Chrome Netbeans IDE Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Wes McClintock
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic