# Projectile logic

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

## 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

Math.

##### Share on other sites

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 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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×