Collision and model damage.

Posted By: MisterEd

Collision and model damage. - 08/17/10 00:45

Im trying to figure out some new stuff. Collisions and subsequent damage to the model(s).

In my test i have two capital ships and i run them into eachother.

I've set up some basic manouvering and shooting and when a collision takes place, my capship just 'halts' and nothing further happens (as intended atm).

My problem is, is that i have no idea what the next step should be to create damage to the models.

Do i need to make a model which consists of a group of models that are 'constructed' in game?

Or do i need to make 1 model and use animations to remove damaged parts of the ship?

Can i have parts breaking off and have it moving through space? I would love to see bits 'n pieces breaking off a capitalship when its in battle.

Can this all be done with the free version om gamestudio?

If anyone could give me some hints in how to approach the damage model and send me in the right direction, i'll try to put the pieces together tongue

My code so far ( which is not all that much ):
Code:
#include <acknex.h>
#include <default.c>


#define STATE 			skill
#define ELEVATION 	skill2
#define COOLDOWN	 	skill4


ENTITY* PLAYER;

// used to check the value on the c_move;
var debugSkill3;

function fire_missile(){
	

	// the local vars
	var temp;
	
	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.5); // small size

	
	vec_for_bone(temp, you ,"main_missile_tube");
	vec_set(my.x,temp) ;


	vec_set(my.pan,you.pan);
	me.pan = me.pan + 90;
	
	my.tilt = you.ELEVATION;


		
	while( 1 ){
		
			
		c_move( my,vector( -10 * time_step , 0 , 0 ),NULL,IGNORE_YOU );
			
		
		if  ( HIT_TARGET ){
			
					
			my.lightrange *= 1+0.5*time_step; 
			vec_scale(my.scale_x , 1+0.5*time_step); // inflate size of the missile
			
			if (my.scale_x > 3) {  
					ent_remove(me); // remove the missile after it has inflated to the max
					
					return;
			}	
		}
		
			
		wait(1);
			
	}
}

function collision_event()
{
	// Oops i hit, in this case,  another capitalship ( capship3_mdl_000 ).
	if(event_type == EVENT_ENTITY) 
	{
			
			 // bring my entity to a halt.
			 my.skill3 = 0;
			 
			 debugSkill3 = my.skill3;
		
	}
}

function move(){
	
	my.emask |= ENABLE_ENTITY; //setting sensitive for collision
	my.event = collision_event; //assign the event-function 
	
	my.skill4 = 1;
	
	while(1){
		
		
		// assign the key combo's
		if(key_w)
			my.skill3 -= 0.1;
			wait(1);
		
			if(key_s)
			my.skill3 += 0.1;
			wait(1);
			
	
		if ( key_d )
			//me.pan -= 2 *time_step;
			me.pan -= 5 *time_step;
			wait(1);
		
		if ( key_a ){
		
			//me.pan += 2 *time_step;	
			me.pan += 5 *time_step;	
			wait(1);	
		}	
		
		if ( key_q ){
			
			
			me.roll += 2 * time_step;	
			my.ELEVATION = me.roll;
			wait(1);
		}
			
		if ( key_z ){			
			
			me.roll -= 2 * time_step;	
			my.ELEVATION = me.roll;
			wait(1);
		}
		
		if ( key_space ){
			
			if ( my.skill4 == 1 )
				ent_create("missile.mdl",vector(me.x,me.y , me.z), fire_missile );
				wait(1);	
				my.skill4 = 2;
		}
		
		
		// after releasing the spacebutton, you will be able to fire the weapon again.
		// its not a gatlaingun.
		// TO DO: some kind of a delay() function for a 'cooldown' period.
		if ( !key_space )
			if ( my.skill4 == 2 ){
				
				my.skill4 = 1;	
				
			}
		c_move (me, vector( 0,  my.skill3 * time_step, 0), nullvector, GLIDE);	
		debugSkill3 = my.skill3;
		wait(1);
		
		
	}	
}
function main(){

	//load the level
	level_load("spacetest2.wmb");
	wait(2); 
	
	// create the capitalship entity
	PLAYER = ent_create  ( "capship2.mdl", vector( 500,3000,400), move );	

	// fixed camera position
	vec_set(camera.x, vector (-100, 3000, 450)); 
	
	// capitalship capship3_mdl_000 is already placed in spacetest2.wmb
	
}



Any comments or suggestions on my code are always welcome as i have no experience in this gamestuff whatsoever.

Ed.
Posted By: Helghast

Re: Collision and model damage. - 08/17/10 08:56

there are several approaches to this, and depending on the game itself, you can do several things.

One solution is to have several models that represent the damage states, then you can use ent_morph to switch to more damaged states every time (this is more for an overal damage to a whole entity); I would consider this the easiest method.

Personally, I would refrain from using animations for damage states at all.
That's me though, maybe other users can correct me on this.

another solution is to use bitmasks, this one is quite tricky though. You setup your model with all the damage states as subgroups. You can then use traces to check which group was hit, and set a group on or off depending on the current damage state.

For debris falling/flying off, you can make models that you can script flying out (using physics maybe even). And for added effects make use of particles (explosion on impact point, then going into smoke. And the debris flying out from the explosion to have fire attached to it) It sounds harder then it actually is, to get a nice particles effect, you can make on in the Tool created for the last contest, and export the code from that.

All this should be able to work in the Free version of A7/A8.

Just my idea's written down here, I hope this helped you out in the right direction, good luck.
If anything else is needed, just write it down, me or someone else will help you out laugh

regards,
Posted By: MisterEd

Re: Collision and model damage. - 08/17/10 22:58

I dont think several diffrent models will do it. I'd like to see diffrent parts of the capitalship to be destructable.

I think bitmasks could work. Havent been able to find the relative functions for that. Suggestions?

Ed.
Posted By: Scorpion

Re: Collision and model damage. - 08/18/10 10:09

you will just need vmask for that...
Posted By: MisterEd

Re: Collision and model damage. - 08/21/10 13:34

I've been playing around with vmask but its not going as i would like to see.

In the example of the online manual there is the line
Code:
your.vmask |= 1<<hit.subset;



As usual, i copy/paste it in my own script and see what happens. Well, when i shot the other capitalship, my own capitalship dissapeared. Its a great Houdini trick but not quite what i was looking for wink

But i must admin, i have trouble reading the vmask line. I have no clue what the |= means.
I've tried debugging the hit.subset but its value remains 0 through the whole script.

I also havent been able to determine which capitalship got hit. No modelname ( hit.model ) or anything else i could think off.

In short, im bogged down tongue.

Below the complete code:
Code:
#include <acknex.h>
#include <default.c>


#define STATE 			skill
#define ELEVATION 	skill2
#define COOLDOWN	 	skill4


ENTITY* PLAYER;

var camera_distance = -200;

// used to check the value on the c_move;
var debugSkill3;
var debugHitx;
var debugHity;
var debugHitz;
var debugMyX;
var onbekend;

function fire_missile(){
	

	
   
    
    
	// the local vars
	var temp;
	
	//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.5); // small size

	
	vec_for_bone(temp, you ,"main_missile_tube");
	vec_set(my.x,temp) ;


	vec_set(my.pan,you.pan);
	me.pan = me.pan + 90;
	
	my.tilt = you.ELEVATION;


		
	while( 1 ){
		
		
		VECTOR trace_target;
  		vec_set(trace_target,vector(2000,0,0)); // the weapon has a firing range of 2000 quants
   	vec_rotate(trace_target, camera.pan);
   	vec_add(trace_target, my.x);
		
			
		c_move( my,vector( -10 * time_step , 0 , 0 ),NULL,IGNORE_YOU );
			
		debugMyX = my.x;
		
		// if the missile misses, it has a 2000 quant livespan
		if ( my.x > 2000 ){
			
			ent_remove(me);
			return;	
		}
		if  ( HIT_TARGET ){
			
				ent_remove(me);
				//your.vmask |= 1<<hit.subset;
				onbekend = hit.subset;
				
				//draw a square where the entity got hit.
				draw_point3d(hit.x,vector(0,0,0),0,25);
				
				//your.vmask |= 1<<hit.subset; // make mesh group invisible 
				
				//without the return, the script crashes and burns when my missile hits the other capship.
				//unsure why that happens.
				return;
				
		}
		
			
		wait(1);
			
	}
}


// collision_event when 2 capitalships fysically run into eachother.
function collision_event()
{
	// Oops i hit, in this case,  another capitalship ( capship3_mdl_000 ).
	if(event_type == EVENT_ENTITY) 
	{
			
			 // bring my entity to a halt.
			 my.skill3 = 0;
			 
			 debugSkill3 = my.skill3;
			 
			debugHitx = hit.x;
			debugHity = hit.y;
			debugHitz = hit.z;
			 
		
	}
}

function move(){
	
	my.emask |= ENABLE_ENTITY; //setting sensitive for collision
	my.event = collision_event; //assign the event-function 
	
	my.skill4 = 1;
	
	while(1){
		
		
		// assign the key combo's
		if(key_w)
			my.skill3 -= 0.1;
			wait(1);
		
			if(key_s)
			my.skill3 += 0.1;
			wait(1);
			
	
		if ( key_d )
			//me.pan -= 2 *time_step;
			me.pan -= 5 *time_step;
			wait(1);
		
		if ( key_a ){
		
			//me.pan += 2 *time_step;	
			me.pan += 5 *time_step;	
			wait(1);	
		}	
		
		if ( key_q ){
			
			
			me.roll += 2 * time_step;	
			my.ELEVATION = me.roll;
			wait(1);
		}
			
		if ( key_z ){			
			
			me.roll -= 2 * time_step;	
			my.ELEVATION = me.roll;
			wait(1);
		}
		
		if ( key_space ){
			
			if ( my.skill4 == 1 )
				ent_create("missile.mdl",vector(me.x,me.y , me.z), fire_missile );
				wait(1);	
				my.skill4 = 2;
		}
		
		
		// after releasing the spacebutton, you will be able to fire the weapon again.
		// its not a gatlaingun.
		// TO DO: some kind of a delay() function for a 'cooldown' period.
		if ( !key_space )
			if ( my.skill4 == 2 ){
				
				my.skill4 = 1;	
				
			}
		c_move (me, vector( 0,  my.skill3 * time_step, 0), nullvector, GLIDE);	
		debugSkill3 = my.skill3;
		wait(1);
		
		
	}	
}
function main(){

	//load the level
	level_load("spacetest2.wmb");
	wait(2); 
	
	// create the capitalship entity
	PLAYER = ent_create  ( "capship2.mdl", vector( 500,3000,400), move );	

	// fixed camera position
	vec_set(camera.x, vector (PLAYER.x - 500, PLAYER.y , PLAYER.z) ); 
		
	
	
	// capitalship capship3_mdl_000 is already placed in spacetest2.wmb
	
}


© 2024 lite-C Forums