Aim Ahead Code


Quite often editors will want to make projectiles aim ahead of their target. The code below will take a projectile and a target and make the projectile aim at the position that the target should reach by the time the projectile reaches it.
veldif=VectorSub(GetThingVel(projectile), GetThingVel(target));
speed=VectorLen(veldif);
distance=VectorDist(GetThingPos(target), GetThingPos(projectile));
time=distance / speed;
moved=VectorScale(GetThingVel(target), time);
meetpos=VectorAdd(GetThingPos(target), moved);
Now you have the position (meetpos) that the projectile needs to aim at. The code below will make the projectile look and travel in the new direction:
lvec=VectorNorm(VectorSub(meetpos, GetThingPos(projectile)));
SetThingLook(projectile, lvec);
projspeed=VectorLen(GetThingVel(projectile));
SetThingVel(projectile, VectorScale(lvec, projspeed));
Note that you have to provide a projectile and target for this code. And be sure to define all of the variables in the symbols section.

Continue


Code provided by *_Seifer_*.