Okay. I've tried it. I have a solution, but I don't know if that's enough for you.

First, what the problem was:
The bones' angles are 0 at startup, while their meshes are already facing each other. So when you set the angles to the angle that a vector pointing towards the position would have, this rotates the bone into that direction, but since the mesh is not pointing into the same direction as the bone, it's messed up.
So what I do now is I find out the angle it has at the beginning (where the meshes are turned into the correct direction) and subtract that from the angle I want to set it at every frame.

Problems that are still there in this version:
- When you tilt the whole entity, the code messes up. Not only my code though, yours as well, the main arm (not only the hydraulics) already messes up when the entity is tilted. I don't know if you need to tilt the entity in your app, so I didn't worry about this for now.
- if the tilt of the arm goes up to 180, it messes up. would limiting it to 179 degrees do the trick for you? or do you need it to go up to 180?

Code:
action Picker()
{			
	var vAngBone1 = 0;
	var vAngBone2 = 0;
	var vAngBone3 = 0;
	var vAngBone4 = 0;
	var vAngBone5 = 0;	
	
	VECTOR gvTemp2;
	ANGLE gvTempAng2;
	VECTOR temp, initialDir;
	
	vec_set(temp2, nullvector);

	c_setminmax(my);
	
	
	ent_bonereset_all(my);
	vec_for_bone(dir1, my, "bone13");
	vec_for_bone(dir2, my, "bone14");
	vec_diff(initialDir, dir2, dir1);
	vec_to_angle(initialAngle, initialDir);
	
	
	while(1)
	{
		my.pan += (key_o - key_p)*time_step*3;
		//my.tilt += (key_k - key_l)*time_step*3;
		
		vAngBone1+= (key_cul-key_cur)*3*time_step; // bone1 angle (base pan)
		ent_bonereset(my, "bone1");
		ent_bonerotate(my,"bone1", vector(vAngBone1, 0, 0)); // rotate bone		
		
		vAngBone2+= (key_cud-key_cuu)*3*time_step; // bone2 angle (base arm tilt)
		vAngBone2 = clamp(vAngBone2, 0, 80);
		ent_bonereset(my, "bone2");
		ent_bonerotate(my,"bone2", vector(0, vAngBone2, 0)); // rotate bone								
		
		ang_for_bone(gvTempAng, my, "bone3");	// get angle of bone3
		ent_bonerotate(my,"bone3", vector(0,-gvTempAng.tilt,0)); // fixed bone angle	
		
		
		
		vec_for_bone(dir1, my, "bone13");
		vec_for_bone(dir2, my, "bone14");
		vec_diff(temp, dir2, dir1);
		vec_to_angle(curAngle, temp);

		vec_diff(temp, curAngle, initialAngle);
		
		ent_bonereset(my, "bone13");
		ent_bonerotate(my, "bone13", vector(0,temp.y,0));
		
		
		// rotate bone 14 in opposite direction:
//		vec_diff(temp, initialAngle, curAngle);
		
		ent_bonereset(my, "bone14");
		ent_bonerotate(my, "bone14", vector(0,temp.y,0));
		

		wait(1);
	}
}



Last edited by Germanunkol; 03/09/11 17:58.

~"I never let school interfere with my education"~
-Mark Twain