Thanks, I have tried to implement your suggestions into my code. However I didn't have much success in doing so.
Standing on a plane the turret is still working fine.
But when its angles are changed (e.g. tilt or roll) it aims at a wrong location.
Nevertheless I think this is the right approach.
This is the code:
Code:
define barrel_handle, skill1;
action ent_turret
{
my.barrel_handle = handle(ent_create("turret_barrel.mdl", my.x, NULL));
while(my) {
you = ptr_for_handle(my.barrel_handle);
var vec_to_ent[3];
var ang_to_ent[3];
vec_diff(vec_to_ent, camera.x, my.x); // direction vector
vec_set(temp, my.pan); // Store the angle in temp
vec_inverse(temp); // Invert the angle
vec_rotate(vec_to_ent, temp); // Rotate the vector
vec_to_angle(ang_to_ent, vec_to_ent); // angle of direction vector
// first rotate the turret's body
ang_rotate(my.pan, vector(ang_to_ent.pan,0,0));
// now rotate the barrel
vec_set(you.pan, my.pan);
ang_rotate(you.pan, vector(0,ang_to_ent.tilt,0));
wait(1);
}
}