cause i´ve no clue how to do that...
Dunno if it´s gravity..


PS.:
This code is JUST FOR jumping..
The movement code is another.


in jump, i trace to the roof and ask for the distance to it. if it´s far enough, i move the object upwards (and sideways if left/right is hitten).
when jumpspeed is at it´s minimum value (10) or the distance to the roof is to small, falling starts.
Now the fall code is the same as jumping.. checking distance to the floor, increasing fallspeed (max 100).
If the distance to the ground is to small, the landing starts (later i want to check speed there, and play 4 different landing animations for the object).

so the code is cut into the following parts (chronological):
jumpstart => jumpgo => fallstart => fallgo => landing

the additional functions are:
jump_player => the process while the player is jumping (switching phases, aksing if space is still pressed)

jump_event => make any other object jump


the current code:
Code:
void landing(ENTITY* obj)
{
	obj.fallspeed = obj.fallspeedold;
	
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	while(obj.roofdist > (obj.objekthoehe/2))
	{
		obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
		c_move(obj, vector(0, 0, -(5*(bulleter/100))*time_step), nullvector, GLIDE | IGNORE_PASSABLE | USE_POLYGON);
		wait(1);
	}
	//obj.z += obj.objekthoehe/2;
	obj.in_jump = 0;
}




void fallgo(ENTITY* obj)
{
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdist > (obj.objekthoehe/2))
	{
		c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
		obj.fallspeed += (obj.gewicht/10.5)*time_step;
		obj.fallspeed = clamp(obj.fallspeed, 0, 100);
	}
	else if(obj.roofdist <= (obj.objekthoehe/2))
	{
		obj.in_jump = 4;
	}
}




void fallstart(ENTITY* obj)
{
	obj.jumpspeed = obj.jumpspeedold;
	obj.fallspeedold = obj.fallspeed;
	
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdist > (obj.objekthoehe/2))
	{
		c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
		obj.fallspeed += (obj.gewicht/10.5)*time_step;
		obj.jumpkeytrigger = 1;
		obj.in_jump = 3;
	}
}




void jumpgo(ENTITY* obj)
{
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdist > (obj.objekthoehe/2) && obj.jumpspeed > 10)
	{
		c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
		obj.jumpspeed -= (obj.gewicht/10.5)*time_step;
	}
	else if(obj.roofdist < (obj.objekthoehe/2))
	{
		obj.in_jump = 2;
	}
	else if(obj.jumpspeed <= 10)
	{
		obj.in_jump = 2;
	}
	else
	{
		obj.in_jump = 2;
	}
}




void jumpstart(ENTITY* obj)
{
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdist > (obj.objekthoehe/2))
	{
		obj.jumpspeedold = obj.jumpspeed;
		c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
		obj.in_jump = 1;
	}
}


//================================================================================================================================================
//================================================================================================================================================
//================================================================================================================================================

void jump_event(ENTITY* obj, var frames, VECTOR* direct, var fall)
{
	obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdist > obj.objekthoehe/2)
	{
		obj.jumpspeedold = obj.jumpspeed;
		c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
		obj.in_jump = 1;
	}
	while(frames > 0 && obj.in_jump == 1)
	{
		jumpgo(obj);
		c_move(obj, vector((direct.x*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
		
		frames -= 1;
		wait(1);
	}
	
	obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.roofdistframe > obj.objekthoehe/2)
	{obj.in_jump = 2;}
	
	if(fall == true)
	{
		while(obj.in_jump != 0 && obj.in_jump != 1)
		{
			if(obj.in_jump == 2)
			{fallstart(obj);}
			else if(obj.in_jump == 3)
			{fallgo(obj);}
			else if(obj.in_jump == 4)
			{landing(obj);}
			
			c_move(obj, vector((direct.y*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
			wait(1);
		}
	}
	
	c_move(obj, vector((direct.z*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
}




void jump_player(ENTITY* obj)
{
	if(key_space == 1 && obj.jumpkeytrigger == 0)
	{
		if(obj.in_jump <= 0)
		{jumpstart(obj);}
		else if(obj.in_jump == 1)
		{jumpgo(obj);}
	}
	else if(key_space == 0 && obj.in_jump == 1)
	{obj.in_jump = 2;}
	else if(key_space == 0 && obj.jumpkeytrigger == 1)
	{obj.jumpkeytrigger = 0;}
	
	
	obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
	if(obj.in_jump == 2)
	{fallstart(obj);}
	else if(obj.in_jump == 3)
	{fallgo(obj);}
	else if(obj.in_jump == 4)
	{landing(obj);}
	else if(obj.roofdistframe > obj.objekthoehe/2 && obj.in_jump != 2 && obj.in_jump != 1)
	{obj.in_jump = 2;}
}




and here the function for creating an object (not finished yet). Later it will include the equipment codes..etc, too.:
Code:
function obj_create(STRING* filename, VECTOR* position, VECTOR* rotation, var gewichtung, var sprungkraft)
{
	ENTITY* creator;
	if(filename != NULL)
	{
		creator = ent_create(filename, position, NULL);
	}
	else
	{
		creator = ent_create(CUBE_MDL, position, NULL);
	}
	vec_set(creator.pan, rotation);
	c_setminmax(creator);
	
	creator.objekthoehe = (creator.max_z*2);
	creator.gewicht = gewichtung;
	creator.in_jump = 0;
	if(sprungkraft != NULL)
	{
		creator.jumpspeed = sprungkraft;
	}
	else
	{
		creator.jumpspeed = 50;
	}
	creator.jumpspeedold = creator.jumpspeed;
	creator.jumpkeytrigger = 0;
	creator.fallspeed = 1;
	
	return(creator);
}



Last edited by Espér; 07/29/11 15:23.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<