L
lolols...
Guest
For a while I have been having trouble to create a fully functional crouching animation for my player character. Just recently I have found a bit of a solution but it is a bit buggy, I'll get to that later.
Right now I have a very important question. How do I properly implement friction in my game? I've tried a few ways but none of them work at all. The reason why I'm asking this along with crouching is because I want it so that the amount of friction increases when my character crouches. The way I want to have it is like being on ice except not as slippery. How would I do this? Huge thanks in advance.
Also, if anybody is interested in solving any bugs with my crouching you could fix, it would be a huge help. You don't need to do it if you don't want to, but if you do, the main bug I'm concerned about is the player quickly switching to its idle animation for a split second while in mid-air if you try to crouch.
Here is my player's code:
Right now I have a very important question. How do I properly implement friction in my game? I've tried a few ways but none of them work at all. The reason why I'm asking this along with crouching is because I want it so that the amount of friction increases when my character crouches. The way I want to have it is like being on ice except not as slippery. How would I do this? Huge thanks in advance.
Also, if anybody is interested in solving any bugs with my crouching you could fix, it would be a huge help. You don't need to do it if you don't want to, but if you do, the main bug I'm concerned about is the player quickly switching to its idle animation for a split second while in mid-air if you try to crouch.
Here is my player's code:
Create Event:
execute code:
///Initialize Variables
grav = 0.4;
hsp = 0;
hsp_carry = 0;
vsp = 0;
movespeed = 1.7;
jumps = 0;
jumpsmax = 2;
jumpspeed_normal = 6;
jumpspeed = jumpspeed_normal
key_down = 0;
ladder = false;
Step Event:
execute code:
///Basic Movement
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord('X'));
key_jump_held = keyboard_check(ord('X'));
key_attack = keyboard_check(ord('Z'));
key_down = keyboard_check(vk_down);
key_up = keyboard_check(vk_up);
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav
//jumping
if (place_meeting(x,y+1,obj_wall))
{
jumps = jumpsmax;
}
else
{
if (jumps == jumpsmax) jumps -=1;
}
if (key_jump) && (jumps > 0)
{
jumps -= 1;
vsp = -jumpspeed;
}
if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-jumpspeed/2)
var hsp_final = hsp + hsp_carry;
hsp_carry = 0;
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Ladder
if (key_up)
{
if place_meeting(x,y,obj_ladder) ladder = true;
}
if (ladder)
{
vsp = 0;
//hsp = 0;
if (key_up) vsp = -2;
if (key_down) vsp = 2;
if !place_meeting(x,y,obj_ladder) ladder = false;
if (key_jump) ladder = false;
}
//Animate
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wall))
{
if (hsp!=0) sprite_index = spr_player_walk; else sprite_index = spr_player_idle;
}
else
{
if (vsp < 0) sprite_index = spr_player_jump ; else sprite_index = spr_player_fall;
}
{
if ladder = true sprite_index = spr_player_ladder;
}
{
if (move!=0) image_speed = 0.3; else image_speed = 0.4;
}
//Crouching
if keyboard_check(vk_down) and (place_meeting(x,y+1,obj_wall))
{
sprite_index = spr_player_crouch;
mask_index = spr_player_crouch;
movespeed = 0;
jumpsmax = 0;
}
else
if keyboard_check_released(vk_down)
{
sprite_index = spr_player_idle;
mask_index = spr_player_idle;
movespeed = 1.7;
jumpsmax = 2;
}
execute code:
///Camera Movement
view_xview[0] += (((x-(view_wview[0]/2)) - view_xview[0]) * 0.5);
view_yview[0] += (((y-(view_hview[0]/2)) - view_yview[0]) * 0.5);
//Parallax Scrolling
background_x[0] = view_xview[0] * 0.05
background_x[1] = view_xview[0] * 0.1
background_x[2] = view_xview[0] * 0.2
background_x[3] = view_xview[0] * 0.3
background_x[4] = view_xview[0] * 0.4
background_x[5] = view_xview[0] * 1.2
execute code:
///Initialize Variables
grav = 0.4;
hsp = 0;
hsp_carry = 0;
vsp = 0;
movespeed = 1.7;
jumps = 0;
jumpsmax = 2;
jumpspeed_normal = 6;
jumpspeed = jumpspeed_normal
key_down = 0;
ladder = false;
Step Event:
execute code:
///Basic Movement
//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(ord('X'));
key_jump_held = keyboard_check(ord('X'));
key_attack = keyboard_check(ord('Z'));
key_down = keyboard_check(vk_down);
key_up = keyboard_check(vk_up);
//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav
//jumping
if (place_meeting(x,y+1,obj_wall))
{
jumps = jumpsmax;
}
else
{
if (jumps == jumpsmax) jumps -=1;
}
if (key_jump) && (jumps > 0)
{
jumps -= 1;
vsp = -jumpspeed;
}
if (vsp < 0) && (!key_jump_held) vsp = max(vsp,-jumpspeed/2)
var hsp_final = hsp + hsp_carry;
hsp_carry = 0;
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
//Ladder
if (key_up)
{
if place_meeting(x,y,obj_ladder) ladder = true;
}
if (ladder)
{
vsp = 0;
//hsp = 0;
if (key_up) vsp = -2;
if (key_down) vsp = 2;
if !place_meeting(x,y,obj_ladder) ladder = false;
if (key_jump) ladder = false;
}
//Animate
if (move!=0) image_xscale = move;
if (place_meeting(x,y+1,obj_wall))
{
if (hsp!=0) sprite_index = spr_player_walk; else sprite_index = spr_player_idle;
}
else
{
if (vsp < 0) sprite_index = spr_player_jump ; else sprite_index = spr_player_fall;
}
{
if ladder = true sprite_index = spr_player_ladder;
}
{
if (move!=0) image_speed = 0.3; else image_speed = 0.4;
}
//Crouching
if keyboard_check(vk_down) and (place_meeting(x,y+1,obj_wall))
{
sprite_index = spr_player_crouch;
mask_index = spr_player_crouch;
movespeed = 0;
jumpsmax = 0;
}
else
if keyboard_check_released(vk_down)
{
sprite_index = spr_player_idle;
mask_index = spr_player_idle;
movespeed = 1.7;
jumpsmax = 2;
}
execute code:
///Camera Movement
view_xview[0] += (((x-(view_wview[0]/2)) - view_xview[0]) * 0.5);
view_yview[0] += (((y-(view_hview[0]/2)) - view_yview[0]) * 0.5);
//Parallax Scrolling
background_x[0] = view_xview[0] * 0.05
background_x[1] = view_xview[0] * 0.1
background_x[2] = view_xview[0] * 0.2
background_x[3] = view_xview[0] * 0.3
background_x[4] = view_xview[0] * 0.4
background_x[5] = view_xview[0] * 1.2