E
Elkrom
Guest
hey guys I'm having some trouble with this wall jump mechanic, if someone can help me out i would be forever grateful. the issue is i cant seem to get the player to jump away from the wall automatically like it does in the tutorial (Shaun Spaldings Wall jump with momentum) no matter what i try the player obj just seems to keep jumping straight up. i think it has something to do with the "hsp = -walljump * hspwjump", in the wall jump section, but I’m not sure. excuse the messy code im pretty new at gml and im just forcing things from multiple tutorials into place until they work.
This is the movement script thats in my player object's step event.
This are the variable in the create event of my player object.
This is the movement script thats in my player object's step event.
Code:
key_right = keyboard_check(vk_right) || keyboard_check(ord("D")) || gamepad_button_check(0,gp_padr);
key_left = keyboard_check(vk_left) || keyboard_check(ord("A")) || gamepad_button_check(0,gp_padl);
key_jump = keyboard_check_pressed(vk_space) || keyboard_check_pressed(ord("W"));
key_crouch = keyboard_check(vk_down) || keyboard_check(ord("S"));
// Input Reaction / Move Left and Right
walljumpdelay = max(walljumpdelay-1,0);
if (walljumpdelay == 0)
{
var move = key_right - key_left;
hsp += move * hsp_acc;
if (move == 0)
{
var hsp_fric_final = hsp_fric_ground;
if (!onground) hsp_fric_final = hsp_fric_air;
hsp = Approach(hsp,0,hsp_fric_final);
}
hsp = clamp(hsp,-movespeed,movespeed)
}
//Walll Jump
if (onwall != 0) && (!onground) && (key_jump)
{
walljumpdelay = walljumpdelay_max;
hsp = -onwall * hspwjump;
vsp = vspwjump;
}
var grav_final = grav;
var vsp_max_final = vsp_max;
if (onwall != 0) && (vsp > 0)
{
grav_final = gravwall;
vsp_max_final = vsp_maxwall;
}
vsp += grav_final;
vsp = clamp(vsp,-vsp_max_final, vsp_max_final);
//// Check if On Ground
onground = place_meeting(x, y+1, obj_wall);
onwall= place_meeting (x + 1, y, obj_wall) - place_meeting(x - 1, y, obj_wall);
if gamepad_button_check(0,gp_padl)
{
key_left = 1;
controller = 1;
}
if gamepad_button_check(0,gp_padr)
{
key_right = 1;
controller = 1;
}
// Jump controller
if gamepad_button_check_pressed(0,gp_padu) || gamepad_button_check_pressed(0,gp_face1)
{
key_jump = 1;
controller = 1;
}
// crouch controller
if gamepad_button_check(0,gp_padd)
{
key_crouch = 1;
controller = 1;
}
// ------------------COLLISIONS---------------
Collisions();
// Animate / character flip where pointing
//if (move !=0) image_xscale = move;
if(key_left)
{
facing = -1;
}
else if(key_right)
{
facing = 1;
}
// Jumping
if (place_meeting(x,y + 1,obj_wall)) {
jumps = jumpsmax;
}
if (key_jump) && (jumps > 0)
{
audio_sound_pitch(snd_jump,random_range(1,1.5))
audio_play_sound(snd_jump,5,false);
//----------Wall Slide Particles
if (onwall !=0) && (!onground)
{
sprite_index = spr_player_wall;
image_xscale = onwall;
var side = bbox_left;
if (onwall == 1) side = bbox_right;
dust ++;
if ((dust > 2) && (vsp > 0)) with (instance_create_layer(side,bbox_top,"Player",obj_dust))
{
other.dust = 0;
hspeed = -other.onwall * 0.5;
}
}
else
{
dust = 0;
}
// Crouching
if (key_crouch) && (crouch = 0){
sprite_index = spr_player_crouch
move = 0;
}
else if (!key_crouch) && (crouch = 1)
{
sprite_index = spr_player
}
// Player Knockback
hsp = (move * movespeed) + gunkickx
gunkickx = 0;
vsp = (vsp + grav) + gunkicky;
gunkicky = 0;
This are the variable in the create event of my player object.
Code:
grav = 0.2;
gravwall = 0.1;
hsp = 0;
hspwjump = 4
hsp_acc = 1;
hsp_fric_ground = 0.5;
hsp_fric_air = 0.15;
vsp = 0;
vspwjump = -5;
vsp_max = 10;
vsp_maxwall = 4;
jumpspeed = 7;
movespeed = 3;
jumps = 0;
jumpsmax = 2;
crouch= 0
controller = 0
firingdelay = 0;
recoil= 0;
controllerangle = 0;
gunkickx=0
gunkicky=0
knife = 0
lazer = false;
draw_xscale = 1;
draw_yscale = 1;
facing = 1;
onwall = 0;
onground =false;
dust = 0;
walljumpdelay = 0;
walljumpdelay_max = 17;
Last edited by a moderator: