Problem with collision help [SOLVED]

Thmask

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):
1626798304627.png


stops and stay there until i move him.
1626797958282.png

Collision works perfectly in other places
1626798861621.png
 

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.
 

Thmask

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.
 

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
 

Thmask

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.
 

Thmask

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
 

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:

Thmask

Member
Solved. Thanks Xer0botXer0, your script wasn't what solved but because of your script it made me think outside of the box, the problem was...well one of the sprites (the idle) was marked in collision check with manual and precise per frame...and the character move the arms down and up so that was the reason why he was colliding with that thing, because the arm was colliding, plus the "fall" sprite was manual and rectangle so them changed between then so the effect of slowly falling happened, that was embaracing LOL.
 
Top