Jump to content
  • Advertisement
Sign in to follow this  
forgetabout

Projectile logic

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

How does the logic of a projectile as in DDTank? Excluding the wind, with an angle and a force as input, how we calculate the trajectory of the projectile until it collides with something?

 

Ps.:Using Python and Pygame

Edited by dromenox

Share this post


Link to post
Share on other sites
Advertisement

Found by googling "projectile motion equations" (give that a try to look at some 500,000 hits): projectile trajectory equations are discussed well here. Those equations are based on initial velocity, rather than "force as input." Assuming by "force" you mean something related to the initial propulsion for the projectile, just convert the initial impulse (force x some-short-time) on the projectile mass to initial velocity.

 

That link discusses the angle to hit particular coordinates if you know your target. To determine if the projectile hits something as it travels, use small increments of time and do your collision detection using calculated x(t) and y(t) values.

 

I'm not familiar with DDTank, and can't help you with Python, I'm afraid.

Share this post


Link to post
Share on other sites

I think googling "projectile motion equations" is going to direct you more toward equations that will help you answer 'where will it land' or 'what launch angle should I use' kind of questions, they'll be useful for AI aiming no doubt.

 

If you want the sort of projectile movement you see in DDTank (which from a cursory googling looks like a worms clone to me), then you're probably more interested in frame by frame movement. Which is even simpler.

 

You're going to have 3 vectors:

 

Acceleration (gravity)

Velocity

Position

 

Each update you need to know the duration of the frame/tick (dt = delta time).

 

void UpdateProjectile(float dt)

{

   Position += Velocity*dt;

   Velocity += Acceleration*dt;

   if (CollisionTest())

   {

      Kaboom();

   }

}

 

Updating the position/velocities of physics objects is known as integration, and that function is the simplest most intuitive approach and should work fine for your needs. There are better approaches which reduce calculation error slightly (verlet integration for example), but that's probably not necessary at this point.

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!