-1
\$\begingroup\$

i'm doing a tower defense game same kingdom rush, enemy can run curve not only linearly.

i found this link : 2D tower defense - A bullet to an enemy

but this link use only for enemy run linearly.

So how to predict target's position in future with enemy can run curve .

p/s : i use this link to make enemy run http://gamedev.tutsplus.com/tutorials/implementation/understanding-steering-behaviors-path-following/

\$\endgroup\$
1
  • \$\begingroup\$ Unless you want your solution to appeal to mathematicians, cheat. \$\endgroup\$ – Marcks Thomas Oct 12 '13 at 21:42
1
\$\begingroup\$

If you're trying to intercept a known curved path it just comes down to algebra, e.g. solve for the line intercepting the parabola.

However if you're talking about adaptive things like steering behaviours, you can't guarantee interception because their trajectory can change at any moment. I think that the best you can do is to cheat a little and ask the enemies what their current path is. General flow below:

  1. Estimate travel time for projectile to reach enemy
  2. Estimate enemy position on spline at that time
  3. Go back to step 1 as many times as desired with new enemy position

Note that you can still miss if they recalculate their path after you shoot.

Edit: pseudocode below

estimated_enemy_pos = current_enemy_pos
for i equals 1 to some_number
    difference = estimated_enemy_pos - gun_pos
    distance = difference.magnitude
    time_to_hit = distance / bullet_speed
    estimated_enemy_pos = spline_pos(time_to_hit)

shoot(estimated_enemy_pos)
\$\endgroup\$
3
  • \$\begingroup\$ Dear david cummins, can you give example or some code, thanks for helping !! \$\endgroup\$ – user919496 Oct 13 '13 at 3:31
  • \$\begingroup\$ what is spline_pos ??? \$\endgroup\$ – user919496 Oct 13 '13 at 14:11
  • \$\begingroup\$ If the enemy is running in some sort of curved path, you need a way to estimate their path. For the sake of argument I'm assuming they are following a spline, which is one formula for a curve that passes through a known set of points. spline_pos would be a function that returns their position on the spline curve at a particular point of time. \$\endgroup\$ – David Cummins Oct 13 '13 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.