Jump to content
jwllorens

Math function request

Recommended Posts

I need a function to rapidly compute some vectors.

Given a position and vectorDir for object A, and position, velocity, vectorUp, and vectorDir for object B.

I need to compute the relative position, velocity, vectorUp and vectorDir for object B such that I can later adjust the position and vectorDir of object A and then update the vectors for object B immediately so that they are the same relative to object A every time.

Imagine a marker and a plane. Imagine the plane is flying away from the marker at some speed, and it is 50m to the south. If I move the marker and rotate it 180 degrees, I want to be able to call the function and set the plane's position to 50m north, rotate the plane so it is facing north, and then set the velocity pointing north.

I am really just focused on the math side of this for now.

Does anyone know how to do this?

Share this post


Link to post
Share on other sites

So you basically want to rotate the plane (and its velocity) around the marker, is that right?

 

A very easy way would be to use a dummy object instead of a marker.

 

1. Save the velocityModelSpace of the plane.

2. Attach the plane to the object at its current position (using worldToModel).

3. Rotate the object as need.

4. Detach the plane

5. Use setVelocity with modelToWorld to restore the saved velocity to the plane.

Share this post


Link to post
Share on other sites

No, I need to do it mathematically. The intent is that I can perform this operation on each element of a large array of data and then use this data to control the plane. Imagine unit capture and unit play, but relative to a point.

Basically, I want to put down a marker or object (just a reference point). Fly the plane and record its positions and velocities relative to the marker. Then I can put down a marker and rotate it dynamically in game and then play back the plane's flight path.

The end-game here is to get an AI pilot to accurately do a gun run wherever I call it in from whichever attack angle I want.

I can handle the scripting but my vector math is rusty

Share this post


Link to post
Share on other sites

Well, how about recording all the data purely in modelspace coordinates. That way you only have to point the plane in the right direction and start the recording.

It may lack accuracy though.

 

 

 

When I did something like that back in A1 I used to just tell the pilot to fly straight toward the target at a decent height and waited till he got close enough. Then a script would take control and keep the plane pointed exactly at the target for a while.

 

 

Try something like this (from the back of my head, not tested...):

while {_alignmode} do {
    _tpos = getPosASL _target;
    _ppos = getPosASL _plane;
    _tdir = _ppos vectorFromTo _tpos;

    _plane setVectorUp[0,0,1];
    _pdir = vectorDir _plane;

    _vdir = _tdir vectorDiff _pdir;
    _vdir1 = _vdir vectorMultiply 0.2;
    _plane setVectorDir (_pdir vectorAdd _vdir1);

    sleep 0.5;
}

That loop should gradually align the plane to the target (the 0.2 specifies how big the adjustments are)

  • Like 1

Share this post


Link to post
Share on other sites

Well, how about recording all the data purely in modelspace coordinates. That way you only have to point the plane in the right direction and start the recording.

It may lack accuracy though.

 

 

 

When I did something like that back in A1 I used to just tell the pilot to fly straight toward the target at a decent height and waited till he got close enough. Then a script would take control and keep the plane pointed exactly at the target for a while.

 

 

Try something like this (from the back of my head, not tested...):

while {_alignmode} do {
    _tpos = getPosASL _target;
    _ppos = getPosASL _plane;
    _tdir = _ppos vectorFromTo _tpos;

    _plane setVectorUp[0,0,1];
    _pdir = vectorDir _plane;

    _vdir = _tdir vectorDiff _pdir;
    _vdir1 = _vdir vectorMultiply 0.2;
    _plane setVectorDir (_pdir vectorAdd _vdir1);

    sleep 0.5;
}
That loop should gradually align the plane to the target (the 0.2 specifies how big the adjustments are)

That may work. In fact it is what i wanted to do. I was going to run the playback to align the plane and do the attack run after the plane got within a certain distance of the target. I would of course need to carefully script a move waypoint or two on the fly to get the plane generally alogned with the tartget.

I also need to do this for helicopters too, I want to me able to set a point and have the heli fly over and hit the point with some unguided rockets.

I might have to play with the vectorUp for that. Thanks for the help.

Share this post


Link to post
Share on other sites

Well, how about recording all the data purely in modelspace coordinates. That way you only have to point the plane in the right direction and start the recording.

It may lack accuracy though.

This is actually very accurate.

1. Record a precise gunrun from a plane approaching precisely from north, attacking a point [0,0,0] in VR.

2. Place any object in any world at any position and direction from where plane should perform their gunrun; vectorUp must be [0,0,1]. Object must not move and/or rotate.

3. Convert all recordings from 1 using modelToWorld command using object from 2 as model and record points as positions. This gives positions in AGL format, convert if BIS_fnc_UnitPlay wants them in other format.

4. Use the data from 3 with BIS_fnc_UnitPlay. Plane will attack object from 2 from object's direction vector.

5. Profit.

 

UPD. For step 1 you can record a gunrun with following turn, so that recording ends at the same altitude and distance to target as when record starts; also plane should be faced towards target and have correspondent vectorUp. That way you can loop gunruns, starting next after previous (having all data converted to that new direction).

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×