Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Akow, degenerate_762), 1,430 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Newbie: Determine orientation tank turret relative to the world #337463
08/10/10 23:53
08/10/10 23:53
Joined: Aug 2010
Posts: 8
Netherlands
M
MisterEd Offline OP
Newbie
MisterEd  Offline OP
Newbie
M

Joined: Aug 2010
Posts: 8
Netherlands
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.

Re: Newbie: Determine orientation tank turret relative to the world [Re: MisterEd] #337480
08/11/10 07:38
08/11/10 07:38
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
Hoi misterEd!

Welcome on the forum, seems for a first effort you're doing really good so far.

A solution to your problem would be to ent_create a rocket on the "end_barrel_bone" (using vec_for_bone), and rotating it with the values of "turret_bone" (using ang_for_bone).

Then using it's own function, you can make it move, have gravity and other effects laugh

Hope that helps, feel free to add me on MSN otherwise, i'd be happy to help (it's in my profile).

regards,

PS: leuk om een mede Nederlander tegen te komen weer eens hier wink


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Newbie: Determine orientation tank turret relative to the world [Re: Helghast] #337546
08/11/10 16:48
08/11/10 16:48
Joined: Aug 2010
Posts: 8
Netherlands
M
MisterEd Offline OP
Newbie
MisterEd  Offline OP
Newbie
M

Joined: Aug 2010
Posts: 8
Netherlands
Thanks for the warm welcome. And thanks for putting me on the right track.

Had some trouble figuring out how to implement those functions. But eventually figured it ( partially ) out.

My updated my shoot_maingun() function.

Code:
function shoot_maingun(){

	me.scale_x= 0.7;
	me.scale_y= 0.7;
	me.scale_z= 0.7;
	my.ambient = 50;  // medium bright
	my.lightrange = 300; // activate dynamic light
	vec_set( my.blue,vector(255,50,50)); // bluish light color
	//set(me,BRIGHT);   // additive blending	
	
	vec_scale(my.scale_x,0.3); // small size
	c_setminmax(my);   // set my bounding box to my real size
	

	// positioning the grenade ( in this case a scaled house, grenade model on todo list )
	// get tank vector in vec_for_bone
	// set the tank vector as the starting point when shooting the gun with vec_set
	vec_for_bone(temp2, you ,"end_barrel_bone");
	vec_set(my.x,temp2);

	//me.STATE = 1;
	
	
	ang_for_bone(temp1, you ,"end_barrel_bone");
	debugValueEndBarrelBoneAngle = temp1;
	me.pan = temp1 - 90;
	
	while(1){
		

		//set(my,FLAG2); 
		
		//if ( me.STATE == 1 )
		
			my.roll += 40*time_step; 
			//c_move( my,vector( 70*time_step,0,0),NULL,IGNORE_YOU );
			c_move( my,vector( 5*time_step,0,0),NULL,IGNORE_YOU );
			
			
	
		
		//if ( me.STATE == 2 )
				
			
		wait(1);
		
	}	

}



It works like a charm now!

In my current code im using the ang_for_bone to get the correct pan but when executed, it seems it shoots in the wrong heading. I had to hardcode '-90' to the grenades pan to get the correct heading.
I'm obviously doing something wrong but have no clue what.

Code:
ang_for_bone(temp1, you ,"end_barrel_bone");
debugValueEndBarrelBoneAngle = temp1;
me.pan = temp1 - 90;



I could use suggestions on the trajectory of the grenade. I take it i gotta adjust c_move on the grenade entity?


Ed
PS. Idd leuk om ook een nederlander tegen te komen. Ik heb overigens geen MSN actief. Misschien dat ik toch maar eens de inlogcodes moet gaan opzoeken tongue

Re: Newbie: Determine orientation tank turret relative to the world [Re: MisterEd] #337594
08/11/10 21:54
08/11/10 21:54
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: MisterEd
I had to hardcode '-90' to the grenades pan to get the correct heading.
You could just rotate the model axis in MED?

Re: Newbie: Determine orientation tank turret relative to the world [Re: MrGuest] #337715
08/12/10 19:26
08/12/10 19:26
Joined: Aug 2010
Posts: 8
Netherlands
M
MisterEd Offline OP
Newbie
MisterEd  Offline OP
Newbie
M

Joined: Aug 2010
Posts: 8
Netherlands
If i knew how that worked tongue

I'll look into it as it is the best sollution tongue.

Thanks,

Ed.

Re: Newbie: Determine orientation tank turret relative to the world [Re: MisterEd] #337780
08/13/10 08:52
08/13/10 08:52
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
open your model in MED (model editor).
goto edit -> transform model global.
then press the "rotate 90 XY" button, untill the model is facing the right way.

The "right way" is when the model's front side is facing towards the right, in the lower left side view.

make sure to remove the -90 from your code now too wink

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1