• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED collision problem

Hello, I am having the most frustrating time trying to understand what I am doing wrong in my code, because the collision works sometimes and sometimes it does not. for example, sometimes I get stuck in the ground right at game start. And i have noticed this only happens when I apply a animation to the player but when I remove the animation the collision works fine. Here is the code I am using. any help is appreciated. PS. I am new when it comes to posting for help on forums so have no Idea if I am posting incorrectly let me know.

/// @description Insert description here
// core player logic


// get player input

key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);


// Caculate movement

var move = key_right - key_left;

hsp = move * walkspd;

vsp = vsp + grv;

if (place_meeting(x,y +1,wall)) and (key_jump)
{
vsp = -jumpsp
}

// Horrizontal Colision

if (place_meeting(x+hsp,y,wall))

{
while(!place_meeting(x+sign(hsp),y,wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;

// vertical Colision

if (place_meeting(x,y+vsp,wall))

{
while (!place_meeting(x,y+sign(vsp),wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

// animation

if (!place_meeting(x,y+1,wall))
{
sprite_index = Knight_jump;
image_speed = 1;
if (vsp > 0) image_index = 1; else image_index = 0
}
else
{

image_speed =1
if (hsp == 0){

sprite_index = Knight_idle2;
}
else
{
image_speed =1
sprite_index = Knight_run2;

}
}
 
Hello, I am having the most frustrating time trying to understand what I am doing wrong in my code, because the collision works sometimes and sometimes it does not. for example, sometimes I get stuck in the ground right at game start. And i have noticed this only happens when I apply a animation to the player but when I remove the animation the collision works fine. Here is the code I am using. any help is appreciated. PS. I am new when it comes to posting for help on forums so have no Idea if I am posting incorrectly let me know.

/// @description Insert description here
// core player logic


// get player input

key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);


// Caculate movement

var move = key_right - key_left;

hsp = move * walkspd;

vsp = vsp + grv;

if (place_meeting(x,y +1,wall)) and (key_jump)
{
vsp = -jumpsp
}

// Horrizontal Colision

if (place_meeting(x+hsp,y,wall))

{
while(!place_meeting(x+sign(hsp),y,wall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;

// vertical Colision

if (place_meeting(x,y+vsp,wall))

{
while (!place_meeting(x,y+sign(vsp),wall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

// animation

if (!place_meeting(x,y+1,wall))
{
sprite_index = Knight_jump;
image_speed = 1;
if (vsp > 0) image_index = 1; else image_index = 0
}
else
{

image_speed =1
if (hsp == 0){

sprite_index = Knight_idle2;
}
else
{
image_speed =1
sprite_index = Knight_run2;

}
}
I figured it out instead of y+1 I put y+10
 

saffeine

Member
another cause for it might be that your collision box changes between sprites.
if any of the sprites have a different origin or different size bounding box, it could be that it's clipping into the ground so it's detecting a collision.
might be worth looking into for the future, but if you have the solution then all the more power to you :)
 
Top