代码如下 interflag=-1 function calculate(I) I:Component_SetIntLogic(10,0,1) I:RequestThrustControl(0) TPI=I:GetTargetPositionInfo(0, 0) AZI=TPI.Azimuth ELE=TPI.Elevation LAV=I:GetLocalAngularVelocity() Roll=I:GetConstructRoll() sinr=math.sin(math.rad(Roll)) cosr=math.cos(math.rad(Roll)) TIP=I:GetTargetInfo(0, 0).Position COM=I:GetConstructCenterOfMass() RP=TIP-COM AziRange2=RP.x^2+RP.z^2 up=0 down=0 right=0 left=0 cruisealtitude=600 --初始阶段:垂直上升到2000以上高度 if AziRange2<160000 then interflag=1 end if interflag<0 then FV=I:GetConstructForwardVector() if COM.y<cruisealtitude-50 then I:LogToHud("第一阶段:高度") I:LogToHud(COM.y) a=-math.deg(math.asin(math.sqrt(FV.x^2+FV.z^2)*sinr)) b=math.deg(math.asin(math.sqrt(FV.x^2+FV.z^2)*cosr)) if FV.y<0 then e=math.deg(math.acos(-FV.y)) if b>0 then b=-e/(180-e)*b end if a>0 then a=-e/(180-e)*a end end --第二阶段:到达目标上空空间 else I:LogToHud("第二阶段:距离") I:LogToHud(math.sqrt(AziRange2)) cosb=(FV.x*RP.x+FV.y*(cruisealtitude-COM.y)+FV.z*RP.z)/math.sqrt(RP.x^2+(cruisealtitude-COM.y)^2+RP.z^2) rr=math.deg(math.asin(FV.y/math.sqrt(1-cosb^2))) if FV.z/FV.x<RP.z/RP.x then if FV.x*RP.x<0 then p=1 else p=-1 end else if FV.x*RP.x>0 then p=1 else p=-1 end end r2=Roll+p*(90+rr) if r2>180 then r2=r2-360 end if r2<-180 then r2=r2+360 end sinr2=math.sin(math.rad(r2)) cosr2=math.cos(math.rad(r2)) a=-math.deg(math.asin(math.sqrt(1-cosb^2)*sinr2)) b=math.deg(math.asin(math.sqrt(1-cosb^2)*cosr2)) if cosb<0 then e=math.deg(math.asin(math.sqrt(1-cosb^2))) if b>0 then b=e/(180-e)*b end if a>0 then a=e/(180-e)*a end end end --第三阶段:俯冲垂直撞击 else I:LogToHud("第三阶段:距离") I:LogToHud(TPI.Range) interflag=1 RV=I:GetConstructRightVector() UV=I:GetConstructUpVector() cosa=(UV.x*RP.x+UV.y*RP.y+UV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2) cosb=(FV.x*RP.x+FV.y*RP.y+FV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2) cosc=(RV.x*RP.x+RV.y*RP.y+RV.z*RP.z)/math.sqrt(RP.x^2+RP.y^2+RP.z^2) if cosb>0 then a=math.abs(cosb)/(math.abs(cosb)+math.abs(cosc))*90 b=math.abs(cosb)/(math.abs(cosb)+math.abs(cosa))*90 else a=180-math.abs(cosb)/(math.abs(cosb)+math.abs(cosc))*90 b=180-math.abs(cosb)/(math.abs(cosb)+math.abs(cosa))*90 end if cosc>0 then a=-a end if cosa<0 then b=-b end end --消除偏角 maxa=0.3 force1=1 force2=0.8 if COM.y<400 then force2=0.3 maxa=0.1 end if a<0 then if LAV.y<maxa then right=force1 else left=force2 end else if LAV.y>-maxa then left=force1 else right=force2 end end if b>0 then if LAV.x>-maxa then up=force1 else down=force2 end else if LAV.x<maxa then down=force1 else up=force2 end end I:RequestThrustControl(8, right) I:RequestThrustControl(9, left) I:RequestThrustControl(10, up) I:RequestThrustControl(11, down) end function Update(I) I:TellAiThatWeAreTakingControl() if I:GetNumberOfTargets(0)>0 then calculate(I) else I:Component_SetIntLogic(10,0,0) end end 其中第三阶段代码可以直接换成 else I:LogToHud("第三阶段:距离") I:LogToHud(TPI.Range) interflag=1 a=AZI b=ELE end 因为这里的AZI ELE 似乎是根据建造的第一个方块来算的而不是几何或质量中心,所以我换成了三维坐标来算。结果发现是一样的?所以这里可以换回来直接a=AZI b=ELE