• 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!

Legacy GM Collision system; player get stuck in wall

C

CptLAN

Guest
Hi i'm actually making a top-down RPG where i made my own movement & collision script, but the problem is that the player get the tendency to get stuck in walls (only about 5-10 pixels) where i need to go in the opposite direction to unstuck, it uses vspeed and hspeed for the movement to be smoother. The player sprite uses a sprite of 50*50 but is smaller than it.Screenshot (37).png Screenshot (36).png
Here's the codes:

w_flag = false
s_flag = false
a_flag = false
d_flag = false

//movements
if keyboard_check(ord('W'))
{if place_free(x,y-global.pl_move_speed)
{vspeed = -global.pl_move_speed
w_flag = true}
else if place_free(x,y-1)
{vspeed = -1
w_flag = true}
else
{w_flag = false}}
else if keyboard_check(ord('S'))
{if place_free(x,y+global.pl_move_speed)
{vspeed = global.pl_move_speed
s_flag = true}
else if place_free(x,y+1)
{vspeed = 1
s_flag = true}
else
{s_flag = false}}

if w_flag = false && s_flag = false
{vspeed = 0}
if keyboard_check(ord('A'))
{if place_free(x-global.pl_move_speed,y)
{hspeed = -global.pl_move_speed
a_flag = true}
else if place_free(x-1,y)
{hspeed = -1
a_flag = true}
else
{a_flag = false}}
else if keyboard_check(ord('D'))
{if place_free(x+global.pl_move_speed,y)
{hspeed = global.pl_move_speed
d_flag = true}
else if place_free(x+1,y)
{hspeed = 1
d_flag = true}
else
{d_flag = false}}

if a_flag = false && d_flag = false
{hspeed = 0}

Hope you'll help me, ty. :]
 

jazzzar

Member
I actually can't read your code for good, use the insert button next time to put some,code but here's how i would go about collision checking for vertical speed,
Code:
If place_meeting(x,y+vspeed,oWall)
{
    While !place_meeting(x,y+sign(vspeed),oWall)
{
   y+=sign(vsp)
}
vspeed=0;
}
Where sign(vspeed) return 1 or -1 based on if vspeed is positive or negative, that will actually cover going up or down, do the same with hor collision, and you should be good to go, and another thing check the mask of the player object and make sure it's a rectangle or square and not using presise collision
 

RangerX

Member
Could it be that you did not factor your movement speed in diagonal? (if you don't adjust it you go faster in diagonal)
 

Roa

Member
Could it be that place_free is rubish?

Is this supposed to be grid based or free key presses?
 
C

CptLAN

Guest
I actually can't read your code for good, use the insert button next time to put some,code but here's how i would go about collision checking for vertical speed,
Code:
If place_meeting(x,y+vspeed,oWall)
{
    While !place_meeting(x,y+sign(vspeed),oWall)
{
   y+=sign(vsp)
}
vspeed=0;
}
Where sign(vspeed) return 1 or -1 based on if vspeed is positive or negative, that will actually cover going up or down, do the same with hor collision, and you should be good to go, and another thing check the mask of the player object and make sure it's a rectangle or square and not using presise collision
I think i understand your code; what i understood by it is that it might wait until the distance to the wall is less than the distance covered then slow the obj until collision to stop it. I'm already using a system doing so but yours is by the way more efficient that mine and can also integrate diagonal check.

Code:
{if place_free(x+global.pl_move_speed,y)
{hspeed = global.pl_move_speed
d_flag = true}
else if place_free(x+1,y)
{hspeed = 1
d_flag = true}
the flag are used to know whether we can stop the obj or not
 

jazzzar

Member
I think i understand your code; what i understood by it is that it might wait until the distance to the wall is less than the distance covered then slow the obj until collision to stop it. I'm already using a system doing so but yours is by the way more efficient that mine and can also integrate diagonal check.

Code:
{if place_free(x+global.pl_move_speed,y)
{hspeed = global.pl_move_speed
d_flag = true}
else if place_free(x+1,y)
{hspeed = 1
d_flag = true}
the flag are used to know whether we can stop the obj or not
so did it work or not?
 
C

CptLAN

Guest
so did it work or not?
i did just realised something your code only detects an object oWall not solids, is there a way to make it able to detect any solid using something else than place_free ?
 
Top