Jump to content
johnnyboy

Calculate intercept position for a moving object

Recommended Posts

I googled this to no avail.  😞

 

I need a sqf function to calculate intercept position to lauch an intercept object at a moving target object.

Known variables:

  • Current Position of target
  • Direction of Target
  • Speed of Target
  • Position of intercept object
  • Speed at which we launch intercept object.

What is target intercept position?

 

Note:  A 2D solution is ok for my use case.

 

Take pity on me...I suck at math!  🙂

Share this post


Link to post
Share on other sites

I would recommend giving this paper a read and applying the concepts into SQF. The paper is about how anti-aircraft targeting systems mathematically determine the orientation of the gun in order to have the bullet intercept the path of a moving target.

  • Like 3
  • Thanks 1
  • Haha 1

Share this post


Link to post
Share on other sites
1 hour ago, SpaceHippo said:

I would recommend giving this paper a read and applying the concepts into SQF. The paper is about how anti-aircraft targeting systems mathematically determine the orientation of the gun in order to have the bullet intercept the path of a moving target.

I do appreciate the link bro.  But I have to laugh, cuz that is WAY above my pay grade. :don9:   I'm really hoping somebody will feed me a fishy (🦈) this time, rather than teach 👨‍🏫 me to fish!  Where is the amazing Mandoble when you need him?  (If you know who that is, then you are old like me).

  • Haha 1

Share this post


Link to post
Share on other sites
On 12/21/2019 at 1:03 AM, johnnyboy said:

I do appreciate the link bro.  But I have to laugh, cuz that is WAY above my pay grade. :don9:   I'm really hoping somebody will feed me a fishy (🦈) this time, rather than teach 👨‍🏫 me to fish!  Where is the amazing Mandoble when you need him?  (If you know who that is, then you are old like me).

Understandable 😆. I wrote two functions similar to what you need a while ago when I first found that pdf. See if you can use them might help some.

Predict future position (3D):

Spoiler

/*
    Description: 

            Retrieves information about a unit a predicts a 
        future position based on various variables.

    Parameters: 

        _target ------------ object*
        _shooter ----------- object*

    Notes:

        - Sparse on variables accounted for
        - Script assumes projectile travels at 881 m/s
*/

// Define Parameters

_target = param [0, objNull, [objNull]]; // object being intercepted
_shooter = param [1, objNull, [objNull]]; // intercepted from where?

// Code:

_targetVel = velocity _target; // velocity in terms of (x,y,z)
_targetPos = getPos _target; //  (position AGLS)

_shooterPos = [
    ((getPos _shooter) select 0),
    ((getPos _shooter) select 1),
    (((getPos _shooter) select 2) + 10)
]; // ^ position of projectile origin calculated with z+10 because my bullets were hitting the ground oops

_distance = _shooterPos distance _target;
_travelTime = (_distance / 881); // time= distance / speed [881 m/s in this case]

_dX = (_targetPos select 0) + ((_targetVel select 0) * _travelTime); // basically figures out how far the target will travel in each direction (x,y,z) within a certain amount time (_travelTime)
_dY = (_targetPos select 1) + ((_targetVel select 1) * _travelTime);
_dZ = (_targetPos select 2) + ((_targetVel select 2) * _travelTime);

_futurePos = [_dX,_dY,_dZ];
_futurePos;


Calculate vectors from one point to another:

Spoiler

/*
    Description: 
            Retrieces the correct vectorDir and vectorUp from one 
        position to another
    Parameters: 
        _pos1 -------------- position *

        _pos2 -------------- position *

    Notes:
        - Script assumes projectile will travel in a straight line (no air resistance, bullet drop etc.)
*/

// Define parameters:

_pos1 = param [0,nil,[[0,0,0]]]; // start point
_pos2 = param [1,nil,[[0,0,0]]]; // end point; vectors returned will point from _pos1 to _pos2

// Code:

_vDir = [
    (_pos2 select 0) - (_pos1 select 0),
    (_pos2 select 1) - (_pos1 select 1),
    (_pos2 select 2) - (_pos1 select 2)
];
_vUp = [ 
    (_pos2 select 0) - (_pos1 select 0),
    (_pos2 select 2) - (_pos1 select 2),
    (_pos2 select 1) - (_pos1 select 1)
];

_vDirAndUp = [_vDir,_vUp];
_vDirAndUp;

 

  • Like 2

Share this post


Link to post
Share on other sites
17 hours ago, SpaceHippo said:

Understandable 😆. I wrote two functions similar to what you need a while ago when I first found that pdf. See if you can use them might help some.

Thanks for not giving up on me dude!  I will definitely try your script.  Much appreciated.

  • Like 1

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

×