SOLVED Collision not being detected

Hello, i've been trying to use this method for checking the collisions on my game (Basically a 2D plataformer), but for some reason it's not working.

GML:
    movingh = hspeed;
    movingv = vspeed;
    
    if (place_meeting(x+movingh, y, obj_Floor)) {
        while (!place_meeting(x+sign(movingh), y, obj_Floor)) {
        hspeed += sign(movingh); // tried x += as well //
        }
    movingh = 0;
    }
The code reaches the while condition normally when in range with the wall, but does nothing.

When i try it this way:

GML:
    movingh = hspeed;
    movingv = vspeed;
    
    if (place_meeting(x+movingh, y, obj_Floor)) {
        while (!place_meeting(x+sign(movingh), y, obj_Floor)) {
        hspeed += sign(movingh); // tried x += as well //
        movingh = 0;
        }
    }
It works but when the !place_meeting becomes true, it freezes the game and i have to force close it.

Any ideas?
Also any suggestions of other methods that can work better? I'm looking forward for something more like "Castlevania SOTN" collision where you can keep running against the wall and the character slides nicely on everything without stopping or getting stuck.
 

FrostyCat

Redemption Seeker
It is not working because you are mixing built-in speed variables (hspeed and vspeed) with manual speed variables (movingh and movingv). This is a huge no-no.

Go back to the tutorial that you were using, and use the exact variable names and operations that it is using instead of making stuff up.
  • DO NOT mix up the position variables with speed variables. Use positions where they are warranted, and speeds where they warranted.
  • DO NOT use the built-in speeds. The tutorial is using a manual setup.
  • DO pay attention to the exact placement of every line of code and understand what they do. You will never get it work for you until that happens.
 
That's something that gets me confused everytime, where to use the speed variables and where not, like, should i use only position variables to move my character around and speed variables just for checks?
 

Nidoking

Member
Position means where something is located. Speed means how fast it is moving. Use position when you want to know or change where it is, and speed when you want to know or change how fast it's moving. If that confuses you, I suggest taking some physics lessons before returning to your programming.
 
I made some tests and i managed to make things work by creating my own variables for speed and not touching the in-built variables, guess i'm gonna stick with that cuz everytime i work with them in my test projects i mess things up lmao. The only in-built variable i used was speed = 0 on my idle state and that at least never gave me headaches hahahaha
Thanks a lot for the replies!
 
Top