Jump to content
  • Advertisement
Sign in to follow this  
newera

Bullet Hit detection

This topic is 4149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!