Gamestudio Links
Zorro Links
Newest Posts
Z12 live performance
by jcl. 06/19/26 11:21
Z9 getting Error 058
by jcl. 06/16/26 09:51
How to select between IB accounts by script?
by AndrewAMD. 06/13/26 15:44
Zorro tutorial ideas?
by AndrewAMD. 06/13/26 15:01
Zorro 3.01 recoded MMI function issue
by 11honza11. 06/13/26 11:40
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
4 registered members (PeWi, vince, Quad, 1 invisible), 4,489 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Student_64151, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
problem in gravity #301318
12/09/09 16:21
12/09/09 16:21
Joined: Jun 2008
Posts: 11
B
birkin Offline OP
Newbie
birkin  Offline OP
Newbie
B

Joined: Jun 2008
Posts: 11
hello everyone,

as in the topic said i have a big problem in my gravity.
I use the khmovement version for lite-c.
and the problem is the following. the movemtent and gravity works well, but the player can went up any gradius of a slope, if it is smaller than 90 degrees.
can someone tell me why this is possible?
and my next question,
Is it possible to tell the player that he can only went up a max gradius of 60 degrees?
I have tried many thing to realize such a function, but because i am only a beginner with things like that,i don´t get anything work....
It would be really nice if someone can tell me how to improve my code to solve my problem.

here is the code i use to test the hole thing...

Code:
#define move_x				skill21
#define move_y				skill22
#define move_z				skill23
#define force_x			skill24
#define force_y			skill25
#define force_z			skill26
#define velocity_x		skill27
#define velocity_y		skill28
#define velocity_z		skill29
#define movement_mode	skill30
#define moving				skill31
#define z_offset			skill32
#define jumping_mode		skill33
#define gravity			skill34
#define z_dist				skill35
#define animate			skill36
#define animate2			skill37
#define animblend			skill38
#define currentframe		skill39
#define blendframe		skill40

#define nullframe	-2
#define blend		-1
#define stand		 0
#define run			 1
#define walk		 2
#define jump		 3
#define fall		 4



VECTOR* camera_move_to = {x=0;y=0;z=0;}
var camera_distance = 200;
var camera_pan;
var camera_tilt;
var temp;
	


var space_press = 0;


VECTOR tempV;
VECTOR tempV2;
ANGLE tempA;

ENTITY* player_weapon;
	


function handle_camera() 
{
	camera_pan -= mouse_force.x * 12 * time_step;
	camera_tilt += mouse_force.y * 8 * time_step;
	camera_tilt = clamp(camera_tilt, -20, 0);
	camera_distance -= 7 * mouse_force.y * time_step;
	camera_distance = clamp(camera_distance,200,450);
	camera.pan = camera_pan;
	temp = fcos(camera_tilt,-camera_distance);
	vec_set(camera_move_to.x, vector(my.x + fcos(camera.pan, temp), my.y + fsin(camera.pan, temp), my.z + 70 + fsin(camera_tilt, -camera_distance)));

	temp = minv(1,0.5 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
	camera.x += temp * (camera_move_to.x - camera.x);
	camera.y += temp * (camera_move_to.y - camera.y);
	camera.z += temp * (camera_move_to.z - camera.z);

	vec_diff(tempV.x, camera.x, my.x);
	vec_normalize(tempV.x, 32);
	vec_add(tempV.x, camera.x);

	if(c_trace(my.x,tempV.x,IGNORE_ME|IGNORE_PASSABLE) > 0) 
	{
		vec_diff(tempV.x, my.x, target.x);
		vec_normalize(tempV.x, 32);
		vec_set(camera.x, target.x);
		vec_add(camera.x, tempV.x);
	}

	vec_diff(tempV.x, my.x, camera.x);
	vec_to_angle(camera.pan, tempV.x);
}

function rotate_entity(rotate_angle,rotate_speed)
{
	if (my.pan == rotate_angle) {return;}
	result = ang(rotate_angle - my.pan);
	if (result > 0) {my.pan += rotate_speed * time_step;}
	if (result < 0) {my.pan -= rotate_speed * time_step;}
	if (ang(rotate_angle - my.pan) < 0 && result > 0) {my.pan = rotate_angle;}
	if (ang(rotate_angle - my.pan) > 0 && result < 0) {my.pan = rotate_angle;}
}

function handle_movement()
{	

	tempV.x = -1000;
	tempV.y = 0;
	if (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) {tempV.x = camera.pan;}
	if (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) {tempV.x = camera.pan + 180;}
	if (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) {tempV.x = camera.pan + 90;}
	if (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) {tempV.x = camera.pan - 90;}
	if (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) {tempV.x = camera.pan + 45;}
	if (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) {tempV.x = camera.pan - 45;}
	if (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) {tempV.x = camera.pan + 135;}
	if (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) {tempV.x = camera.pan - 135;}
	my.moving = 0;
	if (tempV.x != -1000) 
	{		
		my.moving = 1;
		if (key_shift == 1) 
		{tempV.y = 10 * time_step;}
		else
		{tempV.y = 22 * time_step;}
	}	
   
	my.move_x = fcos(tempV.x,tempV.y);
	my.move_y = fsin(tempV.x,tempV.y);
	if(tempV.y > 0)
	{rotate_entity(tempV.x,40);}
	c_move(my,NULL,my.move_x,IGNORE_PASSABLE|GLIDE);
	result =c_trace(vector(my.x,my.y,my.z), vector(my.x,my.y,my.z - 4000), IGNORE_ME | USE_BOX| IGNORE_SPRITES | IGNORE_PASSABLE);
	if(result < 0)
	{
		my.z -= result;
		my.velocity_z = 0;
	}
	if(my.movement_mode == 0) 
	{
		my.gravity = 6;
		if(my.move_x != 0 || my.move_y != 0) 
		{	//if we are moving
			if(my.animblend == stand) 
			{	//if our current animation is stand
				if(key_shift == 1)	my.blendframe = walk;
				else						my.blendframe = run;
			}
			if(my.animblend == run && key_shift == 1)		my.blendframe = walk;
			if(my.animblend == walk && key_shift == 0)	my.blendframe = run;
		}
		else
		{
			if(my.animblend > stand)
			{
				my.blendframe = stand;
			}
		}
	}
}

function handle_gravity() 
{
	result = c_trace(vector(my.x,my.y,my.z), vector(my.x,my.y,my.z - 4000),IGNORE_ME | USE_BOX | IGNORE_SPRITES | IGNORE_PUSH);
	my.z_dist = result;
	if(my.z_dist < 3) 
	{
		if(my.jumping_mode == 0) 
		{
			my.force_z = -1 * result;
			if(key_space == 0 && space_press == 1) {space_press = 0;}
			if(key_space == 1 && space_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				space_press = 1;
				my.jumping_mode = 1;
				my.force_z = 27;
				my.blendframe = jump;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		if(my.jumping_mode == 2 || my.jumping_mode == 3) {my.jumping_mode = 0;}
	} 
	else
	{
		if(my.jumping_mode == 2) 
		{
			if(result > 120) 
			{
				my.animate = 60;
				my.jumping_mode = 3;
			} 
			else
			{my.jumping_mode = 0;}
		}
		if(my.jumping_mode == 3 && result <= 120)		{my.jumping_mode = 0;}
		if(my.jumping_mode == 0 && my.movement_mode == 0) 
		{
			if(result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) 
			{
				my.jumping_mode = 3;
				my.blendframe = fall;
				my.animate2 = 0;
				my.animblend = blend;
			}
		}
		my.force_z -= my.gravity * time_step;
		my.force_z =  maxv(-30, my.force_z);
	}
 	my.velocity_z += (time_step * my.force_z) - (minv(time_step*0.7, 1) * my.velocity_z);
	my.move_z = my.velocity_z * time_step;
}

function handle_animation(var animation_speed) 
{
	if(animation_speed <= 0)	animation_speed = 1; 
	if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
	if(my.animblend == blend) 
	{
		if		 (my.currentframe == stand)	ent_animate(my,"stand",my.animate,ANM_CYCLE); 
		else if(my.currentframe == run)		ent_animate(my,"run",my.animate,ANM_CYCLE);
		else if(my.currentframe == walk)		ent_animate(my,"walk",my.animate,ANM_CYCLE);
		else if(my.currentframe == jump)		ent_animate(my,"jump",my.animate,0);
		
		if		 (my.blendframe == stand)		ent_blend("stand",0,my.animate2);
		else if(my.blendframe == run)			ent_blend("run",0,my.animate2);
		else if(my.blendframe == walk)		ent_blend("walk",0,my.animate2);
		else if(my.blendframe == jump)		ent_blend("jump",0,my.animate2);
		else if(my.blendframe == fall)		ent_blend("jump",60,my.animate2);
		
		my.animate2 += 45 * time_step;
		if(my.animate2 >= 100) 
		{
			my.animate = 0;
			my.animblend = my.blendframe;
			my.blendframe = nullframe;
		}
	}
	//
	switch(my.animblend)
	{
		case stand:
			ent_animate(my,"stand",my.animate,ANM_CYCLE);
			my.animate += 5 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = stand;
			break;
		case run:
			ent_animate(my,"run",my.animate,ANM_CYCLE);
			my.animate += 8 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = run;
			break;
		case walk:
			ent_animate(my,"walk",my.animate,ANM_CYCLE);
			my.animate += 8 * animation_speed * time_step;
			my.animate %= 100;
			my.currentframe = walk;
			break;
		case jump:	//flow through to fall
		case fall:
			if(my.jumping_mode == 3) { my.animate = 60; }
			ent_animate(my,"jump",my.animate,0);
			my.animate += 10 * animation_speed * time_step;
			my.currentframe = jump;
			if(my.animate >= 60 && my.jumping_mode == 1)		my.jumping_mode = 2; 
			if(my.animate >= 100) 
			{
				ent_animate(my,"jump",100,0);
				my.animate = 100;
				my.blendframe = stand;
				if(my.moving == 1) 
				{
					if(key_shift == 1)	my.blendframe = walk;
					else						my.blendframe = run; 
				}
			}
			break;
		}
}



action Arielle()
{
	player = my;
	set(my,POLYGON);
	c_setminmax(my);
	my.gravity = 6;
	my.z_offset = 50;
	while(player != NULL)
	{
		handle_camera();
		handle_movement();
		handle_gravity();
		handle_animation(1);
		wait(1);
	}
}



Re: problem in gravity [Re: birkin] #301361
12/09/09 22:20
12/09/09 22:20
Joined: Oct 2008
Posts: 23
A
ApenasEu Offline
Newbie
ApenasEu  Offline
Newbie
A

Joined: Oct 2008
Posts: 23
Move min Z

There, i believe that is the answear to your problem mate.

Re: problem in gravity [Re: ApenasEu] #301472
12/10/09 21:31
12/10/09 21:31
Joined: Jun 2008
Posts: 11
B
birkin Offline OP
Newbie
birkin  Offline OP
Newbie
B

Joined: Jun 2008
Posts: 11
I have tried around with move_min_z today, but it only changed one thing. I can no longer went up my stairs =)
Or did i use it the wrong way? i have written it in the player action and tried different values...

so i think that was not the solve for my problem, but thanks for the reply =)


Moderated by  HeelX, Spirit 

Gamestudio download | 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