# This is my latest question!!

How do I limit the distance of a projectile?

There are two simple ways, the first one is to save the start position of the projectile in two variables (x and y), then check the distance between this start position and the current one:

[code]Conditions: (Conditions to shoot)
Actions: Create Projectile at Gun.PointX(Barrel); Gun.PointY(Barrel)
Do = Projectile.X() to variable StartX
Do = Projectile.Y() to variable StartY

For each Projectile:
Conditions: sqrt( pow(Projectile.X() - Variable(StartX), 2) + pow(Projectile.Y() - Variable(StartY), 2) ) > MaximumDistance
Actions: Delete Projectile?[/code]
The long expression in just Pythagoras between start and current positions.

Another way is through time, as Velocity = Distance/Time ==> Time = Distance/Velocity (if the projectile has a constant velocity length). As you know the projectile velocity and how much distance it has to travel, you know its lifetime, then just check this time with the current projectile lifetime saved and updated in a variable:

[code]Conditions: (Conditions to shoot)
Actions: Create Projectile at Gun.PointX(Barrel); Gun.PointY(Barrel)

Conditions: No conditions (always)
Actions: Do + TimeDelta() to variable Lifetime of Projectile

For each Projectile:
Conditions: Variable Lifetime of Projectile is > MaximumDistance / ProjectileVelocity
Actions: Delete Projectile?[/code]

EDIT: Please, use an explanatory title