Apexpredator
Member
I am having trouble implementing friction into my game using some code i found on youtube. For some reason the game is ignoring it, at least that is what seems like. i rewrote several times and got nothing, i even changed
the inputs to key_board_pressed and it only made the character stuck. Can you anyone help? thank you in advance.
STEP EVENT
CREATE EVENT
the inputs to key_board_pressed and it only made the character stuck. Can you anyone help? thank you in advance.
STEP EVENT
Code:
//inputs
key_right = keyboard_check(vk_right) or gamepad_button_check(0, gp_padr);
key_left = keyboard_check(vk_left) or gamepad_button_check(0, gp_padl);
key_up = keyboard_check(vk_up) or gamepad_button_check(0, gp_padu);
key_down = -keyboard_check(vk_down) or gamepad_button_check(0, gp_padd);
key_jump = keyboard_check_pressed(ord("Z"))or gamepad_button_check_pressed(0, gp_face1);
key_run = keyboard_check(ord("X"))or gamepad_button_check(0, gp_face2) {run=true}
key_press_left= keyboard_check_pressed(vk_left)or gamepad_button_check_pressed(0,gp_padl);
key_press_right = keyboard_check_pressed(vk_right)or gamepad_button_check_pressed(0,gp_padr);
key_re_left= keyboard_check_released(vk_left)or gamepad_button_check_released(0,gp_padl);
key_re_right = keyboard_check_released(vk_right)or gamepad_button_check_released(0,gp_padr);
// react to inputs
var move = key_right - key_left;
//friction value
fr=.4
if (hsp==0 && vsp==0) idle=true;
else if (hsp!=0 || vsp!=0) idle=false;
// Horizontal movment
if ( key_right|| key_right)
{
hsp=0;
}
if !key_right&& !key_left
{
hsp-=fr*sign(hsp);
{
if inair=false&& key_run
{
hsp = move * movespeed *2;
}
else
{
hsp=move * movespeed;
walk=true;
}
// gravity
if (vsp < 10) vsp += grav;
// jumping
if (key_jump && place_meeting(x, y+1, obj_wall))
{
vsp = -jumpspeed;
;
}
if key_jump
{
if (vsp>-jumpspeed)&&djump =true
{
vsp = -jumpspeed;
djump=false;
}
}
Code:
global.GP = gamepad_is_supported();
///variables
global.levelcomplete=0
rsp=room_speed
global.Health=100
lives=3
global.points=0
//powerups
wreker=false
crusher=false
elctro=false
pyro=false
springtail=false
//movment vars
fr=friction;
vsp=0;
hsp=0;
grav=0.5;
jumpspeed=7;
movespeed=4;
run=false;
hurt=false;
djump=false;
longjump=false;
dift=0
maxspeed=2;
//aimation vars
facing=image_xscale;
inair=false;
idle=false;
walk=true;
highfall=false;
nearedge=false;