Problems with wall jumping

L

Linus Eriksson

Guest
Hi!

I'm having some trouble with wall jumps for my plattformer. I want to make so that when I jump from the wall the character jumps outwards from the wall but it doesn't seem to work. I think it is because of inputs from the left and right key but I don't know how to prevent that. I'll paste my code beneath. Unfortunately some of the explanations are in Swedish, hope it doen't get in the way.


Information about object: obj_character
Sprite: spr_kevin
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask: spr_kevin_run
No Physics Object
Create Event:
execute code:

//Konstanter
move_speed = 1;
max_speed = 8;
flash = 0;


//Jumping
jump = 14;
grav_acc = 1;
grav_limit = 15;

//Variabler
hspd = 0;
hspd_carry = 0;
vspd = 0;
key_down = 0;
dir = 0;
air_timer = 0;
jump_tolerance = 0.1;

//Dash
dash = false;
dash_count = 0;
dash_max = 1;
dash_delay = 0;

//Pounce
pounce = false;
pounce_delay = 0;

//Attack
attack_delay = 0;

//Wall jump
walljumpdelay = 0;
walljumpdelay_max = 17;

//Life count
recently_hit = false;
lives = 1;

Alarm Event for alarm 0:
execute code:

///Alarm for dash
dash = false;
hspd_final = move;
dash_count -= 1;

Alarm Event for alarm 1:
execute code:

///Damage
recently_hit = false;
hspd_final = move;

Alarm Event for alarm 2:
execute code:

///Pounce
pounce = false;
hspd_final = move;

Step Event:
execute code:

//Player input
key_left = -keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_down = keyboard_check(vk_down);
key_jump = keyboard_check_pressed(vk_up);
key_dash = keyboard_check_pressed(ord('Z'));
key_pounce = keyboard_check_pressed(ord('C'));
key_attack = keyboard_check_pressed(ord('X'));
restart = keyboard_check_pressed(ord('R'));

if (restart)
{
game_restart();
}

//Translate input
move = key_left + key_right;
walljumpdelay -= 1;
if (walljumpdelay <= 0)
{
//move right
if (move == 1)
{
hspd += move_speed;
if(hspd >= max_speed) hspd = max_speed;
}
else if (hspd > 0)
{
hspd -= move_speed;
if (hspd <= 0) hspd = 0;
}

//Move left
if (move == -1)
{
hspd -= move_speed;
if(hspd <= -max_speed) hspd = -max_speed;
}
else if (hspd < 0)
{
hspd += move_speed;
if (hspd >= 0) hspd = 0;
}
}

var hspd_final = hspd + hspd_carry;
hspd_carry = 0;

//Gravity

if (vspd < grav_limit)
{
vspd += grav_acc;
}
//Jump
if(place_meeting(x,y+1,obj_block))
{
air_timer = 0;
}
else
{
air_timer += delta_time/1000000;
}

if((key_jump) && (air_timer < jump_tolerance))
{
vspd = -jump;
}


//Wall Jump

//Right Wall
if (place_meeting(x-1, y, obj_block) && !place_meeting(x, y+1, obj_block) && !key_left && !key_right && key_jump)
{
walljumpdelay = 12;
vspd = -jump;
hspd = 5;
}

//Left wall
if (place_meeting(x+1, y, obj_block) && !place_meeting(x, y-1, obj_block) && !key_left && !key_right && key_jump)
{
walljumpdelay = 12;
vspd = -jump;
hspd = -5;
}

//Dash

dash_delay -= 1;

if (place_meeting(x,y+1,obj_block))
{
dash_count = dash_max;
}


if (key_dash && dash = false && (dash_count > 0) && dash_delay < 0)
{
dash_delay = 20;
dash = true;
dir = move;
alarm[0] = room_speed * 0.2;
}

if (dash == true)
{
hspd_final = dir * 25;
instance_create(x,y,obj_dash_effect);
}


//Player Damage

if(place_meeting(x,y,obj_enemy))
{
if !recently_hit
{
flash--
if (flash > 0)
{
sprite_index = spr_kevin_damage;
}
lives -= 1;
recently_hit = true;
alarm[1] = 1 * room_speed;
}
}

if(lives <= 0)
{
room_goto(3);
}


//Room transferance
if (place_meeting(x,y+1,obj_levelEnd))
{
room_goto(4);
}

if (place_meeting(x,y+1,obj_victoryPad))
{
room_goto(5);
}

//Horisontal Colission
if (place_meeting(x+hspd_final,y,obj_block))
{
while(!place_meeting(x+sign(hspd_final),y,obj_block))
{
x += sign(hspd_final)
}
hspd_final = 0;
hspd =0;
}
x += hspd_final;

//Vertikal Colission
if (place_meeting(x,y+vspd,obj_block))
{
while(!place_meeting(x,y+sign(vspd),obj_block))
{
y += sign(vspd)
}
vspd = 0;
}
y += vspd;


//Animation

if(move != 0)
{
image_xscale = move;
}

if (move = -1)
{
with (obj_dash_effect) image_xscale = -1;
}

if(place_meeting(x,y+1,obj_block))
{
if(hspd = 0)
{
image_speed = 0.4;
sprite_index = spr_kevin;

if image_index == 20
{
image_speed = 0;
}
}
else
{
image_speed = 0.8;
sprite_index = spr_kevin_run;
}
}
if (!place_meeting(x,y+1,obj_block))
{
if (vspd < 0)
{
sprite_index = spr_kevin_jump;
}
else
{
sprite_index = spr_kevin_fall;
}
}
 
Top