Im a newbie. Downloaded last weekend the trail version, went throught all the workshops, did some moddeling ( first time ) and map making ( also first time ).

Im testing a tank model just to learn stuff. I have its body turning, moving and the turret is turning independendly.
Got the gunbarrel moving up and down within restricted elevation values.

My problem is, is that my tank has 2 orientations: its body and its turret.

Now i have 'found' a way to get the orientation of the tanks body. Actually, i've set its pan to 270 wink

I've looked at ang_for_bone ( as i have 3 bones in my model ) but i've trouble grasping the concept behind hit. ( same with vec_for_bone ).

What im trying to do is make the damn tank shoot.

I figured i needed a couple of things:

- knowing the gunbarrels orientation,
- knowing the gunbarrels elevation;
- knowing the gunbarrels height, relative to the world 'ground', to be able to calculate a trajectory


Below the code i have so far.
I've used debug to have a look at the values coming from ang_for_bone and vec_for_bone but its not really helping me out.

Any help is appreciated.

Ed.


end_barrel_bone"" is de bone at the end of the barrel.
"turret_bone" is the bone that turns the turret.
"gun_bone" is the bone which makes the barrel go up & down

Code:
//////////////////
//
#include <acknex.h>
#include <default.c>

var debugValueEndBarrelBone = 0;  // y-as
var debugValueEndBarrelBoneAngle = 0; // x-as
var debugValueTurretBone = 0;
var debugValueTurretBoneAngle = 0;
var debugValueGunBone = 0;
var debugValueGunBoneAngle = 0;

var scale = 1;

var temp = 0;
	var temp1 = 0;
	var temp2 = 0;
	var temp3;
	var temp4;
	var temp5;
	var temp6 = 0;

function default_state(){
	
	
	//my.pan = -150;	

	var maxTurretTurnSpeed = 10;
	var gunElevation= 0.1;
	
	var maxElevation = 15;
	var minElevation = -35;
	var elevation = 0;
	
	
	
	
	//scale within the default state
	me.scale_x= scale;
	me.scale_y= scale;
	me.scale_z= scale;
	
	//setting up orientation. Your looking at the front of your tank
	me.pan = 270;
	me.roll = 0;
	me.tilt = 0;
	
	
	// reset all the animations
	// no animations present in the tank model at this time.
	ent_animate( me, NULL, 0, 0); 

	while(1)	{

		
		if ( key_cul ){
			
			
			ent_bonerotate(me, "turret_bone", vector( maxTurretTurnSpeed * time_step, 0, 0));			
			
			wait(1);
			
		}
		
		if ( key_cur ){
			
			ent_bonerotate(me, "turret_bone", vector( -maxTurretTurnSpeed * time_step, 0, 0));
			
			wait(1);	
		}
		
		// ang_for_bone: orientatie van de turret tov de main body!!
		//
		vec_for_bone(temp1, me ,"end_barrel_bone");
		ang_for_bone(temp2, me,	"end_barrel_bone");
		
		//ent_bonemove(me, "turret_bone",vector( temp3,temp4,temp5));
		 
		
		
		vec_for_bone(temp3, me ,"turret_bone");
			
		ang_for_bone( temp4, me,"turret_bone" );
		
			
		//debug data to try and understand what is going on.
		debugValueEndBarrelBone = temp1;
		debugValueEndBarrelBoneAngle = temp2;
		
		debugValueTurretBone = temp3;
		debugValueTurretBoneAngle	= temp4;
		
		
		
		if ( key_cuu ){
			
					
			
			if ( elevation < maxElevation ){
				elevation +=  0.1; 
				ent_bonerotate( me ,"gun_bone",vector(0,  0, -gunElevation * time_step * 10) );
				wait(1);
			}
			
		}
		
		if ( key_cud ){
			
			if( elevation > minElevation ){
				
				elevation -=  0.1; 
				ent_bonerotate( me ,"gun_bone",vector(0, 0, gunElevation * time_step * 10  ) );
				wait(1);	
			}
			
			
		}
		
		
		if (key_a)
			// increase the pan angle of the tank
			me.pan += 3*time_step; 
			
		if (key_d)
			 // decrease the pan angle of the tank
			me.pan -= 3*time_step;
	
	
	
		// move the tank forward
		if(key_s)
		c_move (me, vector( 0, 6 * time_step, 0), nullvector, GLIDE);
		
		// move the tank backward.
		if(key_w)
		c_move (me, vector( 0, -10 * time_step, 0), nullvector, GLIDE);
		
		
	
		wait(1);
		
	}
	
	
}


function main(){

	//load the level
	level_load("testmap2.wmb");
	wait(2); 
	
	// create the tank entity
	ent_create  ( "uglytank2.mdl", vector( 1,1,1), default_state );	
	
	
	// fixed camera position
	vec_set(camera.x, vector (-600, 0, 100)); 
	
	
}



PS. Any comments or suggestions on my code are always welcome.