Jump to content
  • Advertisement
Sign in to follow this  
fightingfalcon

Simulating bullet fire from moving aircraft

This topic is 4928 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 need help in simulating bullet fire from a flying aircraft in 3D environment. Currently, I am using the aircraft velocity vector to compute my bullet's ending position which is wrong or my computation is wrong. What is the formula for the real time trajectory computation with drag and wind factor all added in?

Share this post


Link to post
Share on other sites
Advertisement
The bullet starting velocity should equal the velocity of the firer + ejection velocity.
Drag (and other forces) will then apply to the bullet separately.

I'm assuming you're not implementing a 'hitscan' (hits target instantly) type bullet here.

Share this post


Link to post
Share on other sites
The problem is when my aircraft bank right and fire a bullet, the bullet should fly to my left side but right now, the bullet fly straight. How do I incorporate orientation and angular values so that the bullet behaviour will be correct?

Share this post


Link to post
Share on other sites
Nope, that's correct. The bullet should go straight while your craft turns away from it creating THE IMPRESSION (from the pilot's view) that the bullet is heading left.

Realize that is if the plane is actually flying in an arc, not just "banking to the right". The bullet will tend to go in a straight line as per Newtons happy fun laws unless acted on by outside forces (gravity). Because the launching craft no longer has a way to apply a force to the projectile, any movement it makes after launch will not effect the bullets flight.

Share this post


Link to post
Share on other sites
Your bullets need individual position and velocity vectors. So when you create a bullet, set the bullet position to the position of the gun, and set bullet velocity to ship velocity plus the weapons characteristic velocity. Then at each update, update the position according to the velocity, and modify the velocity according to forces like drag and wind.

Be careful when you say that bullet is flying 'straight'. That is ambiguous. Do you mean straight relative to the ship, or straight relative to your world coordinates?

Straight relative to ship would be 'wrong', and that would be that when you turn the ship, the bullet would magically follow and stay in middle of your sight. This kind of fake bullet may be very easy to implement, because you don't need to store individual velocity, and position could be just be represented as a distance from the wweapon. But since this will not work properly, let's not do it.

Straight relative to world coordinates is mostly 'right'. I say mostly, because once you apply forces like drag and wind and gravity, the flight path is no longer straight.

Share this post


Link to post
Share on other sites
Original post by Aph3x
The bullet starting velocity should equal the velocity of the firer + ejection velocity.
Drag (and other forces) will then apply to the bullet separately.


Aph3x is right, the initial velocity of each individual bullet should be 'velocity of the firer + ejection velocity'

Then every clock cycle, the velocity of the bullet needs to slow down, due to the air resistance.

Each clock cycle the equation to apply to the bullet would be:
velocityOfBullet -= sqrt(2*velocityOfBullet*timeOfClockCycle*F/massOfBullet);

Where 'F' is the drag force and is just a number you'll make up for air.

For reference:
I just used the Newton Kinematic Equation finalVelocity^2 = initialVelocity^2 + 2*acceleration*distanceTravelled to figure this out

Share this post


Link to post
Share on other sites
Are you doing hitscan (instant) bullets, or projectile (moving) bullets?

If you're doing projectile bullets, then you should do as people are suggesting here: give the bullet a direction based on the current direction of the plane when you fire, then maintain that direction independent of where the plane is facing afterwards.

If you're doing hitscan bullets, then I'd suggest, for a more realistic effect, that you base the direction of the bullet on where the plane was a short while ago (< a second, I'd guess, but you'll need to experiment).

Share this post


Link to post
Share on other sites
Quote:
Original post by fightingfalcon
The problem is when my aircraft bank right and fire a bullet, the bullet should fly to my left side but right now, the bullet fly straight. How do I incorporate orientation and angular values so that the bullet behaviour will be correct?


I'm not sure if thats what you mean but you should include angular velocity into the equation too... so instead of just

bullet velocity = aircraft velocity + firing velocity

it should be

bullet velocity = aircraft velocity + cross product of angular velocity of aircraft with position of gun relative to center of mass of aircraft + firing velocity

which essentially is the same as

bullet velocity = gun velocity + firing velocity

note the distinction between gun velocity and aircraft velocity.. these two will not be the same if the aircraft has some angular velocity and the gun is mounted away from the axis of rotation.

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!