I am trying to get my aliens to shoot are where the player's ship will be, rather than where it is at the moment, I have come up with the following (assuming I have the relevant functions correct)
I think it will work, with one main shortcoming, it assumes the range remains constant , when this is not the case. Without giving me an actual answer or a link to one (I am after a challenge here) can anyone let me know if am I barking up the wrong tree and need to use,
a) an iterative approach
b) the right formula
or am I looking for perfection where none is needed, who needs aliens that hit you EVERY time.
range_to_target = range(shooter_x,shooter_y,target_x,target_y) time_to_target = range_to_target / Bullet_velocity x_velocity_difference = target_x_velocity - shooter_x_velocity y_velocity_difference = target_y_velocity - shooter_y_velocity new_target_x = shooter_x + (x_velocity_difference * time_to_target) new_target_y = shooter_y + (y_velocity_difference * time_to_target) bearing_to_target = bearing(shooter_x,shooter_y,new_target_x,new_target_y) spawn_bullet(shooter_x,shooter_y,bearing)
I think it will work, with one main shortcoming, it assumes the range remains constant , when this is not the case. Without giving me an actual answer or a link to one (I am after a challenge here) can anyone let me know if am I barking up the wrong tree and need to use,
a) an iterative approach
b) the right formula
or am I looking for perfection where none is needed, who needs aliens that hit you EVERY time.