I am not sure whether I should post it here because it’s not related to corona, it’s more of a general game programming question but I’m out of ideas after trying with several friends for 3 days now. Here it goes:
Problem statement:
Target leading algorithm for tower defense.
Suppose there is a cannon that can shoot at enemies when it comes into its range. example + explanation of algorithm:http://paul.sc/shooting-moving-target/ (you can find the algorithm too in there but somehow is not working for me)
The problem:
- The cannon shouldn’t target the enemy directly, should shoot where the enemy will be
- We move objects around using transition and supply the x,y and time to get there.
- The enemy moves in segments ex: from (0,0) -> (10, 20) -> (50, 30) each segment is a straight line. So targeting at (10, 19) would miss if we don’t take into account the next segment.
Known:
- Enemy’s x,y position at all times, time to get to a position
- Bullet’s x,y initial position and specified travel time of the bullet (time T) for transition.
Find:
Bullet’s ending position to hit the target with the given time T to be used with the transition function.
We could make the bullets homing but then that would be more costly in processing because:
- It has to be in the enterframe function
- recalculate the angle + position during the enterframe.
I am out of ideas, it should be simple but I can’t seem to figure it out. [import]uid: 11334 topic_id: 4477 reply_id: 304477[/import]
[import]uid: 11334 topic_id: 4477 reply_id: 14217[/import]