Jump to content
  • Advertisement
Sign in to follow this  
jdean300

2d Projectile Collisions with Cover

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

I've been trying to think of good solution for a while but havent thought of one that really feels right, so I was curious to see what suggestions others would have. I'm making a 2d top down military game and I'm having trouble with how to handle bullets when an enemy is in cover. Currently, my AI can get in to cover and it will block all projectiles. But, let's say there is some thing like a barrel that an enemy is hiding behind. ideally, some bullets would collde with the barrel, and some would not. Another part of the problem is what if there is another object in between that a projectile has to pass over.

 

I thought about giving the projectile a height when it is first created, and then have that adjust by some constant random velocity and have that height factored in to collisions, but that could cause some outlandish issues where the projectile is missing and colliding with the ground or going over the enemy's head when it should not, and with the aiming height not being controlled by the player, this seems like it would become very frustrating. A player is going to expect the height of the game area to be mostly irrelevant because of the 2d top-down style, so using that with collisions seems wrong.

 

I could set a flag on the barrel itself, saying that their is an enemy taking cover behind it, and then force some projectiles to collide with the barrel and others to pass over it. Then, if an enemy was in a ducking state he would be safe from bullets. The problem I see here is complexity of the enemy talking with the barrel to set a flag to tell the physics system to allow some projectile to pass and others not, and then needing to check the enemy's state to see if he is low enough.... it just seems like a lot of communication between many different objects/systems.

 

So, what are some other ways this could be accomplished? Or does one of my ideas seem appropriate?

Share this post


Link to post
Share on other sites
Advertisement

I would just give the projectiles a random fake height when spawned and the cover objects and whatever else a value for their max height and allow them to go through when they exceed that. It's simple and it will work consistently for all objects in the scene. The height variation can always be in the 0-player height range. 

Share this post


Link to post
Share on other sites


ideally, some bullets would collde with the barrel, and some would not. Another part of the problem is what if there is another object in between that a projectile has to pass over.

 

the traditional way to handle this is objects provide a percentage of cover.

 

"all barrels provide 50% cover".

 

so each attack has a 50% chance to hit the barrel, instead of traveling on to the target.

 

so you do a raycast from shooter to target, checking for intervening cover. when you hit intervening cover, you do your percentage check. if the check fails, the shot hit the cover. draw some bullet holes, play a sound effect - next bullet. if it makes it all the way to the target, then your resolve the attack (projectile hit).

 

you can also do stuff like "all barrels provide 50% cover, 90% if the target is crouching."

Share this post


Link to post
Share on other sites

What happens when you just shoot a bullet at the barrel and there's no-one behind it?  Will it hit the barrel 50% of the time?

 

I think it needs to be consistent, making it so, if there's a figure crouched behind a barrel, bullets now hit the barrel 90% of the time doesn't seem like valid gameplay to me.

 

Whatever you choose, try and make it consistent, whether a player is taking cover behind the object or not.

Share this post


Link to post
Share on other sites


What happens when you just shoot a bullet at the barrel and there's no-one behind it?  Will it hit the barrel 50% of the time?

 

top down 2d - remember? no different than a turn based tabletop wargame as far as combat rules goes - such as squad leader. whether the dev wants to draw some bullet holes and dust clouds as eye candy when the player shoots at barrels is up to them. for the typical "max gameplay effect" most devs opt for, you'd draw the eye candy every time. which of course means you need to move the bullet full distance first to see what it hits if anything (player, wall etc), then move back to the barrel if it can't hit something more interesting.

 

a simpler trick would be just do traditional stepped movement with collision checks as usual, and if you hit a barrel and fail the "dice roll", it draws the eye candy, else it travels on to the next obstacle. if that's the player and they are crouched, reduce chance to hit about 50%, as the size target they present is about 1/2 of non-crouched. that way you don't have to worry about proximity of barrels and players.  the two basic mechanics (IE game rules) of "barrels stop 50% of all bullets" and "crouching makes 50% of bullets miss" combine to give you the dynamic of "crouched player behind barrel has 75% cover".

 

 

 

the next step past that is multiple elevations (ground, slope, hilltop), and basic 3D LOS/LOF calculations as seen in panzer leader and panzer blitz by avalon hill.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!