• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Object Player gets stuck at corners between wall and floor

Wizer13th

Member
Hi everyone,

New to programming, I've been following Shaun Spalding's platformer tutorial, updated will wall jumps coding.

Wall jumping works perfectly fine. The problem I have comes with collision.
Let's say my object Player collides with a corner made by my object wall. In the coding, if his collision box collides with the bottom and left or right, it gets stuck, since both hsp and vsp = 0 at the same time.
In his previous videos, his project wasn't hindered by this issue. How can I get around this one ?

Here's the Step Event coding :

#region Movement
if (global.disabled == false){

// Get player input
keyLeft = keyboard_check(vk_left) || keyboard_check(ord("A"));
keyRight = keyboard_check(vk_right) || keyboard_check(ord("D"));
keyActivate = keyboard_check_pressed(vk_space);
keyAttack = keyboard_check_pressed(vk_shift);
keyItem = keyboard_check_pressed(vk_control);

/* Pour plus tard avec zones échelles
keyUp = keyboard_check(vk_up) || keyboard_check(ord("W"));
keyDown = keyboard_check(vk_down) || keyboard_check(ord("S"));
var move = point_direction(0,0,keyRight-keyLeft,keyDown-keyUp);
*/

walljumpdelay = max(walljumpdelay-1,0);
if(walljumpdelay == 0)
{
var dir = keyRight-keyLeft;
hsp += dir * hsp_acc;
if(dir ==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,-hsp_walk,hsp_walk);
}

// wall jump
if(onwall != 0) && (!onground) && (keyActivate)
{
walljumpdelay = walljumpdelaymax;
hsp = -onwall * hsp_wjump;
vsp = vsp_wjump;

hsp_frac = 0;
vsp_frac = 0;
}

var grav_final = grav;
var vsp_max_final = vsp_max;
if(onwall !=0) && (vsp > 0)
{
grav_final = grav_wall;
vsp_max_final = vsp_max_wall;
}

vsp += grav_final;
vsp = clamp(vsp,-vsp_max_final,vsp_max_final);

// Jump
if(jumpbuffer > 0)
{
jumpbuffer --;
if(keyActivate){
jumpbuffer = 0;
vsp = vsp_jump;
vsp_frac = 0;
}
}


//dump fraction and get final integer speeds
hsp += hsp_frac;
vsp += vsp_frac;
hsp_frac = frac(hsp);
vsp_frac = frac(vsp);
hsp -= hsp_frac;
vsp -= vsp_frac;


//COLLISION
if (place_meeting(x + hsp, y, oWall)){
var onepixel = sign(hsp);
while (!place_meeting(x+onepixel, y, oWall)) x += onepixel;
hsp = 0;
hsp_frac = 0;
}

x = x + hsp;


if (place_meeting(x , y + vsp, oWall)){
var onepixel = sign(vsp);
while (!place_meeting(x, y+onepixel, oWall)) y += onepixel;
vsp = 0;
vsp_frac = 0;

}

y += vsp;

// animation
onground = place_meeting(x,y+1,oWall);
// +1 if wall right of us, -1 if wall is left of us
onwall= place_meeting(x+1,y,oWall) - place_meeting(x-1,y,oWall);
if (onground) jumpbuffer = 8;
//adjust sprite
image_speed = 1;
if (hsp != 0) image_xscale = sign(hsp);
if (!onground)
{
if (onwall != 0)
{
sprite_index = sPlayerWall; // à créer
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, "Instances", oDust))
{
other.dust = 0;
hspeed = -other.onwall*0.5;
}
}
else
{
dust = 0;
sprite_index = sPlayerAir;
image_speed = 0;
image_index = (vsp > 0);
}
}
else
{
if (hsp != 0) sprite_index = sPlayerRun ; else sprite_index = sPlayerIdle;
}

}

Any help is welcome, and thank you all for your precious time. ;)
 

Wizer13th

Member
And now for some reason, it works perfectly... Guess I'll never understand. But I did change my origin point from bottom center to middle center, so that's the best explanation I can come up with.
 
Top