1 registered members (AndrewAMD),
1,014
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Player movement bug??
[Re: PadMalcom]
#426515
07/24/13 08:04
07/24/13 08:04
|
Joined: Jun 2013
Posts: 108 Alberta, Canada
CanadianDavid
Member
|
Member
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:
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
Gino_Fabrizio
OP
Newbie
|
OP
Newbie
Joined: Jul 2012
Posts: 45
|
Ok, thanks for your reply. This is the player_action:
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 and the movement 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 its the code, thanks
Last edited by Gino_Fabrizio; 07/26/13 13:42.
|
|
|
|