您需要“预测”敌人的方向。假设它沿着直线移动,塔需要观察它的目标的速度和方向。
假设您的塔位于点 (0,0),并且您收集了目标的两个观测值:
- (100, 100) 在
t=0
- (90, 95) 在
t=1
Speed: First calculate the distance between this two points:
d = sqrt((x2-x1)^2 + (y2 - y1)^2) =
= sqrt(10^2 + 5^2) = sqrt(125) = 11.18034
So the speed of your target is 11.18034 (since you took the observations in an interval equivalent to one time-unit)
Angle: A bit of geometry. The slope of the trajectory is:
m = (y2 - y1) / (x2 - x1) =
= 5 / 10 = 0.5
So the angle is:
theta = arctan(0.5) = 0.463648 radians (or 26.56 degrees)
With two points and the slope, you can estimate the trajectory of your target:
y - y1 = m * (x - x1)
==> y = 0.5 * (x - 100) + 100 =
= 0.5 * x + 50
All that remains is to calculate the point where your missile can intercept the target. For that you'll need to know the speed of your missile and then calculate the "optimal" interception point. I'll leave you this second step to you. It's simple geometry (and a bit of creativity)