How would you go about calculating when to begin descending on a target when you know the angle of descent, but to reach the angle of descent the direction vector arcs like it would in real life. I'm very bad at math and terminology but I hope you get what I mean.(adsbygoogle = window.adsbygoogle || []).push({});

You know the targets position in 3 space. And the missiles position, velocity, etc.

The arcing algorithm (that changes the missiles direction over time to a desired direction) is done like this:

If the code isn't clear enough I can explain in english, just let me know. This changeDirection() method gets called each tick for the missile until it is facing the correct direction.

Any links or tips would be appreciated, thanks.Code (Text):

void Missile::changeDirection(const Point3F& newDirection, const S32 axis)

{

F32 diff = 0.0f;

mTargetDir = newDirection;

mAxis = axis;

isChangingDir = true;

F32 speed = mCurrVelocity.len();

mCurrVelocity.normalize();

F32 unitsOfTurn = mDataBlock->precision * 0.01; // arbitrary number

mTargetDir.z - mCurrVelocity.z

if ( axis & Z )

{

if ( (diff = newDirection.z - mCurrVelocity.z) > 0 )

{

mCurrVelocity.z += unitsOfTurn;

if ( mCurrVelocity.z > newDirection.z )

{

mCurrVelocity.z = newDirection.z;

}

}

else if ( diff < 0 )

{

mCurrVelocity.z -= unitsOfTurn;

if ( mCurrVelocity.z < newDirection.z )

{

mCurrVelocity.z = newDirection.z;

}

}

}

if ( axis & X )

{

if ( (diff = newDirection.x - mCurrVelocity.x) > 0 )

{

mCurrVelocity.x += unitsOfTurn;

if ( mCurrVelocity.x > newDirection.x )

{

mCurrVelocity.x = newDirection.x;

}

}

else if ( diff < 0 )

{

mCurrVelocity.x -= unitsOfTurn;

if ( mCurrVelocity.x < newDirection.x )

{

mCurrVelocity.x = newDirection.x;

}

}

}

if ( axis & Y )

{

if ( (diff = newDirection.y - mCurrVelocity.y) > 0 )

{

mCurrVelocity.y += unitsOfTurn;

if ( mCurrVelocity.y > newDirection.y )

{

mCurrVelocity.y = newDirection.y;

}

}

else if ( diff < 0 )

{

mCurrVelocity.y -= unitsOfTurn;

if ( mCurrVelocity.y < newDirection.y )

{

mCurrVelocity.y = newDirection.y;

}

}

}

if ( mCurrVelocity == newDirection )

{

isChangingDir = false;

}

mCurrVelocity *= speed;

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Missile turning toward target

**Physics Forums | Science Articles, Homework Help, Discussion**