Bullet Hit detection

Started by
4 comments, last by Daivuk 17 years, 2 months ago
Hello all, I am making a 2D top down tile based game. I would like to know the best method for detecting what a bullet hits on its path. I have done some research and it appears I should use some sort of ray-casting technique. I am not sure how to go about implementing one in 2D since most variations seem to derive from some sort of spatial partitioning structure. Is there an easier method? I'm I way off base? Any help is greatly appreciated. Thanks, Tony.
Advertisement
Tony, in 2D, the bullet's path is a line, and anything it hits will be a line, or can have a border made up of lines, so collision detection can be done with simple line/line intersection tests. Spatial partitioning may be used to quickly eliminate large groups of objects that the bullet definitely will not hit.

The bullet's speed will generate a line from frame to frame, and that is the line to test for intersection with other lines in the game space. I hope this helps.
if you want to test the collision detection when your bullet hits the tile for that instance you can use the if/else statement.
You are right. The bullet trajectory is a ray which is cast from the gun and stretches out to infinity. The bullet then hits the first object that intersects the ray.

An often-used approach is to partition space into a grid, which makes raycasting easier to perform (since you only need to check grid tiles that intersect the ray). An example can be found in the metanet tutorial B.

For slower-moving projectiles, deepsender's suggestion of a swept area algorithm works as well, and is equivalent to detecting all ray hits that occur earlier than the future bullet position.

Quote:Original post by Middle_Pro
if you want to test the collision detection when your bullet hits the tile for that instance you can use the if/else statement.


And variables.
Thank you guys so much :)

-Tony
If your game is tiled based. You just need to know which cells to test against.
That can be done with a simple rasterize technic.

This topic is closed to new replies.

Advertisement