Problem with collision help [SOLVED]

Member
I'm having a problem with collision, for some reason if you be in a exactaly spot (the border of the block) your character will slowly enter the block switching in colliding and not colliding, and then after a some progress he stops, i have no ideia why it happens, the white rectangle behind him is his collision mask and the red block it's the wall, here's my collision script:

//collision
if place_meeting(x + hsp, y, oWall){
while !place_meeting(x + sign(hsp), y, oWall){
x += sign(hsp);
}
hsp = 0;
}

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

the numbers 1 and 0 represents if he's colliding with the wall ( the above is for Y collision and the lower is for X), and when he's in that state (slowly entering the block) he keeps changing between 1 and 0, and then he stops after a while, the number keep in 0 (since now he's colliding), but what i wanna know is, why he enter the conor of block since the rectangle is colliding with the red block, how to solve it.

PS: he works perfectly if not be in that exactaly border of the block (it counts for all blocks)
PS 2: he have the exactaly same collision mask for all sprites&frames

slowly entering the block (it counts for every other red block no matter where is while is possible to collide with the border):

stops and stay there until i move him.

Collision works perfectly in other places

Nidoking

Member
If you're approaching the corner like that, there's no collision on the x-axis, and no collision on the y-axis. You don't perform any motion if there's no collision along that axis (presumably, you do movement along both axes later and didn't post that part). So, if the collision only happens on a diagonal, you're not checking for it. Usually, you'd apply movement on one axis before checking the other axis.

Member
If you're approaching the corner like that, there's no collision on the x-axis, and no collision on the y-axis. You don't perform any motion if there's no collision along that axis (presumably, you do movement along both axes later and didn't post that part). So, if the collision only happens on a diagonal, you're not checking for it. Usually, you'd apply movement on one axis before checking the other axis.
no the movement happens before the collision check on the same step event, this is the script.
//movement
hsp = (key_right - key_left) * spd

ideas ?

roknix

Member
Hello,

did u check if the Collision Mask of the player is a rectangle and fitting to your sprite?

If I change this im getting a close result.

Xer0botXer0

Senpai
Do bounding boxes adjust with x and y/scale ?
How are you setting your vsp ?

Last edited:

MaxLos

Member
Where are you changing the player's x/y coordinates if there isn't a collision? I think that's what Nidoking was referring to, usually after the collision check on a specific axis is when
you should move the player, so for example:

Code:
``````if place_meeting(x + hsp, y, oWall)
{
while !place_meeting(x + sign(hsp), y, oWall)
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;  //<--- Apply horizontal movement immediately after Horizontal collision check``````
Same for the vertical collision

Member
Hello,

did u check if the Collision Mask of the player is a rectangle and fitting to your sprite?

If I change this im getting a close result.
yup is a rectangle and is fitting on the sprite, the collision mask it's that white rectangle behind the sprite.

Xer0botXer0

Senpai
Alright and does your character spawn on the oWall or above and land fine ?

Member
Where are you changing the player's x/y coordinates if there isn't a collision? I think that's what Nidoking was referring to, usually after the collision check on a specific axis is when
you should move the player, so for example:

Code:
``````if place_meeting(x + hsp, y, oWall)
{
while !place_meeting(x + sign(hsp), y, oWall)
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;  //<--- Apply horizontal movement immediately after Horizontal collision check``````
Same for the vertical collision
my x/y update is the last thing on my step event, after the collision check there's just a change sprite script, but to be sure i done what you say but no, same effect, still the same problem

Member
Alright and does your character spawn on the oWall or above and land fine ?
spawn above the land

Last edited:

Xer0botXer0

Senpai
This works on my side:
GML:
``````hspd = 0;
hspd_multiplier = 2;
grav = 0.2 ;
terminal_velocity = 5;
vspd = 0;``````

GML:
``````var key_right = keyboard_check(ord("D"));
var key_left = keyboard_check(ord("A"));
hspd = (key_right - key_left) * hspd_multiplier;

if !place_meeting(x + sign(hspd),y,oWall)
{
x += hspd;
}

if place_meeting(x,y + vspd,oWall)
{
vspd = 0;
}
else
{
if (vspd <= terminal_velocity)
{
y += vspd;
vspd += grav;
}
else {y += vspd;}
}``````

Last edited: