# Need math help for script.

## Recommended Posts

I am having some trouble with a script. I need to accomplish two things.

I have a plane that is AI controlled, and a three dimensional point in space. What I want to do is shut off the AI and get the velocity of the plane, and then within a loop get angle of the plane and incrementally adjust the angle of the plane until it is pointing at the three dimensional point, and with each increment set the velocity to be the scalar equivalent of what it was at the start of the script but pointing straight ahead. In this loop I will check the distance and force the plane to fire the gun and whatnot, and then call off the script and re-enable the AI.

How do I incrementally adjust a direction vector until it is pointing at a point in space? How do I adjust the direction of a velocity vector to make it point in the same direction that the plane is pointing in?

Maybe I should use this?

The problem is I really don't understand the vectorUp format in Arma.

Edited by jwllorens

##### Share on other sites

vector up represents the direction in which the top of the object is pointing (Like if you would sitck an arrow pointing up on top of the model). But I guess you need vectordir here.

What might work is :

1)write this vectordir plane vector in spherical coordinates.

2)compute and write the direction of the target point in spherical coordinates as well.

3)Update angles theta and phi : theta(t+dt) = theta(t)+deltat_theta, phi(t+dt) = phi(t)+deltat_phi (each delta should be inversely proportional to the difference between the angle you want to reach and your current angle. This will avoid brutal rotations).

4) check if theta and phi ar close to the wanted values which correspond to the target direction. If not repeat from step 1

It could be fun to make, but if your target is static, you could instead record/play a path using this:

Edited by super-truite
clarification

##### Share on other sites

Thanks! The idea is that the target is not static, and is marked on the map. An real AI unit then makes the gun run. This allows the CAS to be unavailable if it gets shot down and have realistic timing values for take off, landing, number of flares, ect, and the unit is always present on the map. I could then also control ingress and egress directions by moving waypoints. All I need is to get that script working that will manuever the plane into a precise gun run when it is near a certain position. I can then run the script, record the impact location and the starting location, and it should be easy to extrapolate from there when to run the script when calling in a gun run to hit a precise location.