[GameMaker Studio 2] - Perfect Top Down, Platformer, RPG Collisions
Вставка
- Опубліковано 8 вер 2024
- Getting stuck is no fun. Getting stuck in a wall in a video game is just the worst, so let's make sure that doesn't happen. Whether you're creating a platformer, RPG, top down shooter, or any other kind of game, if you've got moving objects, you need to control how they collide. I'll show you the best way to do that, and explain exactly how it works.
Finished Project: drive.google.c...
Social:
- Connect with me on Twitter @Aaron_LLTT: / aaron_lltt
- Become a valued Patron and receive more exclusive content @: / letslearnthistogether
- Wanna hear from other developers in the industry? Head on over to my podcast, DevTalk, to listen to engaging conversations I have with various successful developers: devtalk.buzzsp...
My Exclusive Courses💻🎮:
- Bundle Course Package & More Here! www.letslearnt...
Music courtesy of OC Remix.
Hey, the collision logic here is a bit wrong.
The order currently looks like this:
1. Check collision along x
2. Check collision along y
3. Move along x
4. Move along y
This can result in getting stuck when moving diagonally.
Correct order should be:
1. Check collision along x
2. Move along x
3. Check collision along y
4. Move along y
thank you so much!! you absolute legend!! I majorly appreciate it :D
I really need to practice this more. I found this method on Shawn Spaulding's Platformer guide, I redid it entirely from memory one day, total success, then tried again the following day to no avail. just couldn't replicate it again for some reason. but I see it's the same system. I feel this method is far superior to place_free since we can completely forgo using the Black Box "Solid" property, and feels smoother while at it.
This collision code is great! Btw, is it possible you can make a video about using a "z axis" in 2D, so the player can jump and be on top of platforms (using this system)? That'd be great!
Can't wait for more.
I dont know why but instead of writting :
if (place_meeting (x + hMove, y, oWall))
{
while (!place_meeting (x +sign(hMove), y, oWall))
{
x += sign(hMove);
hMove = 0;
}
}
And putting the "hMove" in the "while", putting it in the if like this :
if (place_meeting (x + hMove, y, oWall))
{
while (!place_meeting (x +sign(hMove), y, oWall))
{
x += sign(hMove);
}
hMove = 0;
}
solves the problem, in the first example I would get stuck against the wall and couldn't move anymore.
Hope this helps to anyone who has the same problem!
Thanks now I can sleep
Gracias me sirvió.
This code doenst work on my project. Wtf should i do more????
What exactly isn't working? Are you getting an error message? I can't help without more info.
Thanks. :D
How would I make it so I dont get stuck when another collision is meeting with another collision (example enemy and player collide)
The same system should work for you. You just add in a check for them as well, usually with a parent system so you're not checking every single enemy.
@@LetsLearnThisTogether im using the system. When both me and the enemy run into eachother i get stuck kinda i have to move a certain way to get out
Sorry if this is a dumb question, but instead of moving 1 pixel at a time, why not just move the difference between the player and the solid (which we know is less than the regular move speed)?
That’s a great question. The goal is to move that distance. But we don’t know what it is, and it could be different every time we run into a solid, so we have to do a loop to find where it is and then stop.
There might be some other solutions which grab the sprite, figure out the bounding box and the side we’re approaching, but I think that may be even more complex. Might be worth trying out though.
@@LetsLearnThisTogether I appreciate the response!
quick question is this safe with precise masking objects?
It can be, but it can also cause an issue if you’re changing the sprite near a wall, as it could get caught in there if it’s not symmetrical.
love u