BOOL vec_move_to(VECTOR *vFrom, VECTOR *vTo, var speed) // It returns TRUE upon arrival, otherway returns FALSE
{
VECTOR vRay;
vec_diff(&vRay, vTo, vFrom); // Get movement ray
if(abs(vRay.x) + abs(vRay.y) + abs(vRay.z) == 0) // Early return on null rays
return TRUE;
var length = vec_length(&vRay); // Get ray length
var step = abs(speed) * time_step; // Get movement step with negative speed guard
if(length > step) // If the ray is longer than the step
{
vec_scale(&vRay, step / length); // Shorten the ray to the length of the step. WARNING: The result of the division of the factor can be zero on low speeds or high frame rates.
vec_add(vFrom, &vRay); // Add the result to the origin vector
return FALSE;
}
// Otherway, the ray is shorter or equal to the step
vec_set(&vFrom, vTo); // Copy vTo into vFrom
return TRUE;
}