I post the complete code here
Code:
ENTITY* tur;
PANEL modelang {
digits(5, 130, "tilt: %f", *, 1, tur.tilt);
flags = VISIBLE;
}
view etur1_view = {
layer = 1;
pos_x = 470;
pos_y = 360;
size_x = 130;
size_y = 100;
arc = 20;
aspect = 1;
ambient = 10;
fog = 10;
//genius = null;
flags = VISIBLE;
}
function main()
{
video_switch(6,0,2);
level_load("bonetest.wmb");
wait(3); // wait until the level is loaded
//mouse_mode = 2; // now show the pointer
camera.x = -200;
camera.z = 100;
camera.tilt = -25;
}
action turret()
{
tur = me;
while (player == NULL) { wait(1); }
var temp2;
while (1)
{
my.tilt += mouse_force.y;
vec_for_bone(temp2, me, "bone2");
vec_diff(temp, player.x, temp2.x);
vec_to_angle(temp2, temp);
ent_bonereset(me, "bone1");
ent_bonereset(me, "bone2");
//pan
ent_bonerotate(me,"bone1", vector(temp2.pan, 0, 0));
//tilt
ent_bonerotate(me,"bone2",vector(0, temp2.tilt, 0));
// attach a camera to the front of barrel
vec_for_vertex(temp, me, 170);
vec_set(etur1_view.x, temp);
ang_for_bone(etur1_view.pan, me, "bone2");
wait(1);
}
}
action satellite
{
player = me;
while (tur == NULL) { wait(1); }
var rotAng = 0;
while(1)
{
rotAng = (rotAng - time_step) % 360;
my.x = tur.x - 200 * sin(rotAng);
my.y = tur.y + 200 * cos(rotAng);
my.z = sin(total_ticks * 5 + 1000) * 80;
wait(1);
}
}
The model has 2 bones, a satellite move orbit around the entity. I want to Entity constantly look at the satellite, if the entity tilt is 0, everything fine.

But if the entity tilt is non-zero, it cannot look at the satellite correctly. I think because if the entity tilt has change, the bone1 will move bone2, causing the code vec_to_angle not work as expected.

You may download my test project here [35K]:
bone.zip