Java Game Physics - Determine intersection and collision detection

Sh4d0wsPlyr

My question can actually be broken down into two parts. The first, is what is a reasonable method for determining collision in a Java game? My second, is how to find the point of collision for use later?

Originally I was implementing a rudimentary collision system using a thread I found earlier with a simple method for finding a collision in a polygon. I have posted the code below. However as best I can tell, this will not show me the collision point, and I would have to do something separate to find it.

public boolean collisionDetection(int charX, int charY) {
    if(boundry == null)
        return false;

    int numVert = boundry.length;
    boolean ret = false;
    for(int i = 0, j = numVert - 1; i < numVert; j = i++) {
        if (((boundry[i].y >= charY) != (boundry[j].y >= charY)) && (charX <= (boundry[j].x -boundry[i].x) * (charY - boundry[i].y) / (boundry[j].y - boundry[i].y) + boundry[i].x)) {
             ret = !ret;
        }
    }
    return ret;
}

But I had a thought while working on this... Let us presume that I input my coordinates into the system as Points. I did them in order (e.g. point 1 -> point 2 -> point 3 -> point 1).

Knowing the points are in a connected order (e.g. they form the boundary of the object), is it then logical to say I could just use a number of line intersection methods to find if the character intersected with the border of my polygon? I know the characters current position, as well as the intended position.

Any thoughts, or if you have a suggestion a better implementation method?

Rob85

you need to be doing either point to pint or box to box collision See my answer here

this explains two methods of collision detection. its in 3D but just drop the third axis and can be used for 2D. Hope this helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Bullet physics collision detection

From Dev

Collision detection in java 2d game

From Dev

Collision detection in javascript game

From Dev

XNA - Farseer Physics 3.5 - Collision Detection Issues - No/Zero Gravity - Space Game

From Dev

Libgdx collision detection with Physics Body Editor

From Dev

Javascript Canvas Game - Collision Detection

From Dev

Collision detection in javascript canvas tanks game

From Dev

Trying to use quadtrees for collision detection in a game

From Dev

Game score via collision detection increment

From Dev

Trying to use quadtrees for collision detection in a game

From Dev

Collision Detection for fast moving game object in Unity

From Dev

Problem with collision detection is JS canvas game

From Dev

Processing color collision detection (java)

From Java

Java: Pacman collision detection with wall

From Dev

Java Circle to Circle collision detection

From Dev

Java Circle to Circle collision detection

From Dev

HTML Canvas game: 2D collision detection

From Dev

game viewport focus vs collision detection on y axis against gravity

From Dev

Collision detection in 2D game without tiles XNA

From Dev

Collision Detection in FPS Game using three.js

From Dev

if statement in JavaScript game not working as desired to allow for collision detection

From Dev

Phonegap game development collision detection regarding different screen sizes

From Dev

Collision detection in 2D game without tiles XNA

From Dev

game viewport focus vs collision detection on y axis against gravity

From Dev

Collision Detection in FPS Game using three.js

From Dev

Collision Detection not working in cocos2dx v3 using Physics

From Dev

Libgdx Box2d collision detection using physics body editor

From Dev

Collision detection between two rectangles in java

From Dev

Trouble with java 2D collision detection

Related Related

  1. 1

    Bullet physics collision detection

  2. 2

    Collision detection in java 2d game

  3. 3

    Collision detection in javascript game

  4. 4

    XNA - Farseer Physics 3.5 - Collision Detection Issues - No/Zero Gravity - Space Game

  5. 5

    Libgdx collision detection with Physics Body Editor

  6. 6

    Javascript Canvas Game - Collision Detection

  7. 7

    Collision detection in javascript canvas tanks game

  8. 8

    Trying to use quadtrees for collision detection in a game

  9. 9

    Game score via collision detection increment

  10. 10

    Trying to use quadtrees for collision detection in a game

  11. 11

    Collision Detection for fast moving game object in Unity

  12. 12

    Problem with collision detection is JS canvas game

  13. 13

    Processing color collision detection (java)

  14. 14

    Java: Pacman collision detection with wall

  15. 15

    Java Circle to Circle collision detection

  16. 16

    Java Circle to Circle collision detection

  17. 17

    HTML Canvas game: 2D collision detection

  18. 18

    game viewport focus vs collision detection on y axis against gravity

  19. 19

    Collision detection in 2D game without tiles XNA

  20. 20

    Collision Detection in FPS Game using three.js

  21. 21

    if statement in JavaScript game not working as desired to allow for collision detection

  22. 22

    Phonegap game development collision detection regarding different screen sizes

  23. 23

    Collision detection in 2D game without tiles XNA

  24. 24

    game viewport focus vs collision detection on y axis against gravity

  25. 25

    Collision Detection in FPS Game using three.js

  26. 26

    Collision Detection not working in cocos2dx v3 using Physics

  27. 27

    Libgdx Box2d collision detection using physics body editor

  28. 28

    Collision detection between two rectangles in java

  29. 29

    Trouble with java 2D collision detection

HotTag

Archive