Floating point Collsion Detection

I have an player that move around in a 2D map. The value of x and y are in floating points. Now i want it to collide with another player that move around too in the map. Both the player can rotate around too. I have tried many ways including rectangle drawing to detect collsion but its not accurate or very wrong.

Is there any hint on how to do the collsion detection? I really need help..Or is there anyone with similar situatio please give some tips or codes....

Any help will be greatly appreciated. Thank You!!!!

[537 byte] By [Hanz_05a] at [2007-11-27 7:50:03]
# 1
some times ago i developped a little app with a chara you can make walk into a room, where he collides and stops when he touches wallsi can give you that code if you wish, but not right now since i'm at work :)
calvino_inda at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...
# 2

I would suggest using spheres around your "objects", or rectangles depending on the shape of your objects. Then you can use basic math to check if two objects collide.

You may want to look up the math behind this yourself, but I'm sure you can find a math library that you can either use or port to java. Looking around sites such as gamasutra.com and gamedev.net might give you some valuable clues.

If your objects have odd shapes (a gun sticking out for example), you may want to use multiple collision tests per object, having multiple bounding boxes or spheres.

gimbal2a at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...
# 3

Thanks but i tried using rectangles. Since the x and y are float type, i have to convert to integer to use the rectangle. And when i intersect with other player rectangle, it will immediately detect collision.

For example,

Rectangle rec=new Rectangle((int) x,(int)y, 32,32);

/ / since the image size is 32px by 32px

Then it will not be accurate.

Hanz_05a at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...
# 4

You normally put, as said eariler, a bounding box around each object. This is normally a circle/sphere. This is done as it is trivial to determine if two spheres intersect (so it can be done very fast and very often). When you determine that two spheres intersect you try more complex methods to determine if the objects they contain have actaully touched each other. In 3D this tends to involve analysis of the polygons making up each object. In 2D this can be done by cheking if the bitmasks for both objects intersect.

matfud

matfuda at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...
# 5
I will try again using rectangle....Message was edited by: Hanz_05
Hanz_05a at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...
# 6

Let me confirm something...

Rectangle rec=new rectangle(x,y,32,32);

I have a 32 by 32px image. So the above parameters is correct? In order to draw the rectangle? But when i move my player, it detect collision immediately even when

Bu whent i use this way,

Rectangle rec=new rectangle(x,y,1,1);

The collision is working but not that accurate. It can still sometimes go through half of the enemy image.

Same as the enemy too.

Hanz_05a at 2007-7-12 19:31:03 > top of Java-index,Java Essentials,Java Programming...