Code:
stock VelocityFromAtoB(const Float:originA[3], const Float:originB[3], const Float:speed, Float:output[3])
{
output[0] = originB[0] - originA[0];
output[1] = originB[1] - originA[1];
output[2] = originB[2] - originA[2];
new Float:length = vector_length(output);
output[0] *= (speed / length);
output[1] *= (speed / length);
output[2] *= (speed / length);
}
Then you can use it like this:
Code:
new Float:playerOrigin[3], Float:entityOrigin[3];
entity_get_vector(id, EV_VEC_origin, playerOrigin);
entity_get_vector(ent, EV_VEC_origin, entityOrigin);
new Float:speed = 300.0; // units per second
new Float:velocity[3];
VelocityFromAtoB(entityOrigin, playerOrigin, speed, velocity);
entity_set_vector(ent, EV_VEC_velocity, velocity);
__________________