• 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 Need help with Physics collision checks

T

That BioMechanical Dude

Guest
I'm making a Physics-based platformer and I encounter the following issue: when the player object moves left and right, while in mid-air, and bumps into a wall, it slides on that wall, which slows down the object's falling speed. It's probably because of the nature of the physics engine. The object has some horizontal velocity, which pushes it against the wall, causing it to slow down. I don't want this behavior, so I change the code for when the player presses left or right:

Code:
if !(physics_test_overlap(x+phy_speed_x, y, phy_rotation, obj_wall)) {
  physics_apply_force(x, y, 110, 0)
}
However, a new problem arises. The player object can't move left or right when on it's on the ground (which is also obj_wall), only when it's in mid-air, and I think I know why. When using x and y for collisions, GML takes the whole collision mask (or in this case, fixture) into account (so that x+1 would be one pixel to the right of the entire object, not just the origin). The function obviously checks if certain objects are overlapping and indeed, after making the fixtures visible, I can see that the bottom of the player object overlaps with the top of obj_wall.

So, is there a way to fix this? Some other function I can use to check for a collision? Please let me know.
 
T

That BioMechanical Dude

Guest
Tried it, but now I'm back with the original problem again. For some reason, the player object slides on the wall and slows down, even though it doesn't really make sense.
 
T

That BioMechanical Dude

Guest
Well, it does, but there's obviously a side effect: the player object doesn't stop moving left and right.

There's gotta be some way to do a proper collision detection. Does anyone have any other ideas?
 

Jakylgamer

Member
ok ignore the friction part and set the restitution for the wall to 0 , it seems its the bounce thats making it "slide"
 
T

That BioMechanical Dude

Guest
Hmmm... It seems to work fine. I've also discovered that when making a collision check with place_meeting, you shouldn't use stuff like x+phy_speed_x, but actual numbers like x+4, otherwise it doesn't work. I don't know why that is, exactly, so if someone has an idea, feel free to share it.

Anyway, thanks for the help, Jakylgamer! :)
 
Top