Jump to content
  • Advertisement
Sign in to follow this  
ravinDavin

Bullet Collisions

This topic is 2396 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

Hey, I was wondering about a good approach for testing collisions between bullets and enemy/player.

Currently, anytime the player fires, a new bullet object is added to a list of active Bullets. If the list size > 0 then it loops through each bullet. First I have a BSP check, to see if its in the same sector as the enemy. Then I have a rectangle test, and then per pixel.

But I would also like to be able to hit the player with enemy bullets.
What is the best way to do this?
Should I just add the enemies bullets to the same active Bullets list? Or since there is only 1 player, should I put directly in the update() method of the bullet class.(Everytime a bullet is updated, it checks if it is in same sector as player, then rectangle and perpixel).

Or should I have 2 separate lists for enemies and player?

Also, the way I am checking for collisions with the enemy(because there is more than 1) is looping through each active bullet, and then looping through an enemy that it may collide with. Is this how it normally goes? With a double for loop?

Share this post


Link to post
Share on other sites
Advertisement
If your enemies are all in the bsp tree, can you not use that bsp check ONCE to determine the smallest AREA the bullet may intersect within the next frame. then only test that bullet against all enemies within that area.

do not do this test per enemy as that would be a waste. the ideas is one bsp tree parse to find a list of enemies for the bullet to do more detailed testing against.

then for each enemy, do box, and then per pixel. but only if you want the bullet to pierce through the first enemy and hit a second. if it can only hit one enemy, then you merely stop testing on the closest enemy that it this. you can easily sort the enemies in the area list by closest and test each until you hit one. that would be the only enemy that could be hit by the bullet.

enemy bulets vs you. why not just make it a general system to test anything in the path of a bullet.. so your own bullets could bounce back at you and hurt you if they could bounce to start with and enemies could end up shooting each other when trying to shoot at you...

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!