One note:
Code:
...
...
ratio = (speed/target_distance);
if(target_distance >= speed) // If we need to go father than we can in one cycle...
{
x_pos += tar_vx * ratio;
y_pos += tar_vy * ratio;
if(tar_vz>2)
z_pos += tar_vz * ratio;
else
z_pos = z;
}
else //If we are with-in our one cycle distance...
{
x_pos = x;
y_pos = y;
z_pos = z;
}
...
...
Should be:
Code:
...
...
if(target_distance >= speed) // If we need to go father than we can in one cycle...
{
ratio = (speed/target_distance);
x_pos += tar_vx * ratio;
y_pos += tar_vy * ratio;
if(tar_vz>2)
z_pos += tar_vz * ratio;
else
z_pos = z;
}
else //If we are with-in our one cycle distance...
{
x_pos = x;
y_pos = y;
z_pos = z;
}
...
...
Since ratio is only used in there, no point in wasting cycles on the division.