Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Player movement bug?? #426502
07/23/13 21:51
07/23/13 21:51
Joined: Jul 2012
Posts: 45
G
Gino_Fabrizio Offline OP
Newbie
Gino_Fabrizio  Offline OP
Newbie
G

Joined: Jul 2012
Posts: 45
Hi, im making my first person shooter game, zombie like! grin
I have a lot of fun programming this, and so on, but I have an error on the movement of the player. When he walks (using the terrain.hmp), he stucks and dont glide for a second in the mountains of the ground and then walk, I dont know why, I dont know how to fix this... I set his flags to NARROW | FAT , and so on. Thanks

Re: Player movement bug?? [Re: Gino_Fabrizio] #426503
07/24/13 03:16
07/24/13 03:16
Joined: Jun 2013
Posts: 108
Alberta, Canada
C
CanadianDavid Offline
Member
CanadianDavid  Offline
Member
C

Joined: Jun 2013
Posts: 108
Alberta, Canada
Likely the player's bounding box is getting stuck in jagged terrain. You should set the bounding box a little higher than the player itself so that it isn't dragging on the floor. You will also have to adjust your code so that the gravity does not always force the character's bounding box to the floor.

Re: Player movement bug?? [Re: CanadianDavid] #426506
07/24/13 06:16
07/24/13 06:16
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey Gino, show us your player movement code please.

@David: When he sets the bounding box higher, the player code will most likely set it to the ground again so that the player's feet will disappear in the terrain.

Re: Player movement bug?? [Re: PadMalcom] #426515
07/24/13 08:04
07/24/13 08:04
Joined: Jun 2013
Posts: 108
Alberta, Canada
C
CanadianDavid Offline
Member
CanadianDavid  Offline
Member
C

Joined: Jun 2013
Posts: 108
Alberta, Canada
@PadMalcom Yes, I'd imagine his player movement code is dragging the bounding box on the floor. A smaller bounding box could be made and instead of simply using a c_trace from my.x, calculate the distance from the player's feet and the ground via:
Code:
VECTOR* my_feet;
c_trace(my.x, vector(my.x,my.y,my.z-5000), IGNORE_ME | IGNORE_PASSABLE);
vec_for_min(my_feet, me);
dist_down = my.z + my_feet.z - target.z;


where dist_down > 0 means we have to apply gravity still.

@Gino See c_move example for a simple movement code. In the comments you'll notice that the bounding box shouldn't be dragging on the floor.

Re: Player movement bug?? [Re: CanadianDavid] #426641
07/26/13 13:38
07/26/13 13:38
Joined: Jul 2012
Posts: 45
G
Gino_Fabrizio Offline OP
Newbie
Gino_Fabrizio  Offline OP
Newbie
G

Joined: Jul 2012
Posts: 45
Ok, thanks for your reply. This is the player_action:

Code:
action player_action()
{
	player = me;
	my.health = 100;
	my.eflags |= FAT | NARROW;
	set(my, INVISIBLE);
	player.z = 150;
	camera.arc = 80;
	//vec_set(my.min_x, vector(-20, -20, -40));
	//vec_set(my.max_x, vector(20, 20, 40));
	my.min_z *= 0.5;
	wait(1);
	ent_create(CUBE_MDL, nullvector, flashlight_action); // flashlight
	c_updatehull(my, 1);
	player_movement();
	player_camera();
}



forget the flashlight part tongue

and the movement code:


Code:
function player_movement()
{
	var resistance = 100;
	var key_space_off = 1;
	var jump_wait = 0;
	var rest = 0;
	var step_wait = 0;
	var step_random = 0;
	var step_last = 0;
	var move_speed = 10;
	var fire = 0;
	var reloading = 0;
	set(pan_health_hud, SHOW);
	random_seed(0);
	while(player.health > 0)
	{
		// Gravity
		if (c_trace(my.x, vector(my.x, my.y, my.z - 1000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_BOX) > 5) absdist.z -= 2 * time_step;
		else absdist.z = 0;		
		
		if (key_shift && resistance > 0) move_speed = 15;
		else move_speed = 10;
		
		dist.x = move_speed * (key_w - key_s) * time_step;
		dist.y = move_speed * (key_a - key_d) * time_step;
		
		if ((key_w || key_s || key_a || key_d || key_space) && key_shift) resistance -= 0.5 * time_step;
		if (resistance <= 0) key_shift = 0;
		
		if ((key_d || key_a || key_w || key_s) && step_wait <= 0) 
		{
			while (step_random == step_last) step_random = integer(random(4)) + 1;
			step_last = step_random;
			if (step_random == 1) snd_play(snd_footstep1, 75, 0);
			else if (step_random == 2) snd_play(snd_footstep2, 75, 0);
			else if (step_random == 3) snd_play(snd_footstep3, 75, 0);
			else if (step_random == 4) snd_play(snd_footstep4, 75, 0);
			if (key_shift && resistance >= 0) step_wait = 15;
			else step_wait = 25;
		}
		if (resistance <= 0)	
		{
			if (rest == 0) snd_play(snd_breath, 80, 0);
			if (rest <= 35)
			{
				rest += 0.35 * time_step;
				if (rest >= 35) 
				{
					resistance = 40;
					rest = 0;
				}
			}
		}
		
		if (key_space && result <= 5 && key_space_off && jump_wait <= 0 && resistance > 0)
		{
			absdist.z = 7.5;
			key_space_off = 0;
			jump_wait = 30;
		}
		else if (!key_space) key_space_off = 1;
		
		if (key_t) player.health -= 5;
		
		if (ent_pistol != NULL)
		{
			if (mouse_left == 1 && fire == 0 && ent_pistol != NULL)
			{
				if (weapon_bullets > 0)
				{
					fire = 1;
					snd_play(snd_fire, 80, 0);
				}	
			}
			if (fire == 1 && my.skill50 < 100)
			{
				ent_animate(ent_pistol, "shoot_a", my.skill50, ANM_CYCLE);
				my.skill50 += 10 * time_step;
			}
			else if (my.skill50 >= 100)
			{
				weapon_bullets -= 1;
				my.skill50 = 0;
				fire = 0;
			}
			if (key_pressed(key_for_str(str_reload_key)) && weapon_bullets < 12 && weapon_loads > 0 && reloading == 0)
			{
				reloading = 1;
				// sonido de recarga
			}
			if (reloading == 1 && my.skill50 < 100)
			{
				ent_animate(ent_pistol, "reload", my.skill50, ANM_CYCLE);
				my.skill50 += 8 * time_step;
			}
			else if (my.skill50 >= 100)
			{
				weapon_bullets = 12;
				weapon_loads -= 1;
				my.skill50 = 0;
				reloading = 0;
			}			
		}			
		
		move_friction = 0;
		c_move(my, dist, absdist, IGNORE_PASSABLE | GLIDE);
		if (ent_pistol != NULL) c_move(ent_pistol, dist, absdist, IGNORE_PASSABLE | GLIDE);
		
		if ((key_shift == 0 || (key_shift == 1 && key_w == 0 && key_a == 0 && key_s == 0 && key_d == 0)) && resistance < 100 && rest == 0) resistance += 0.3 * time_step;
		if (step_wait > 0) step_wait -= 3.5 * time_step;
		if (jump_wait > 0) jump_wait -= 3.5 * time_step;
		wait(1);
	}
	// Death Animation;
	set(my, PASSABLE);
	var tempPos = c_trace(camera.x, vector(camera.x, camera.y, camera.z - 1000), IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_BOX);
	tempPos = target.z + 20;
	while(camera.z > tempPos)
	{
		camera.z -= 1.5 * time_step;
		if (camera.tilt > (-80)) camera.tilt -= 1 * time_step;
		wait(1);
	}
	wait(-0.5);
	snd_stopall(4);
	lose_screen();
}



I made my self "resistance" code, when the player run it slow down and then he cant run for a while tongue

its the code, thanks laugh

Last edited by Gino_Fabrizio; 07/26/13 13:42.

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