Move And Collide with Slopes - Gamemaker Tutorial
Вставка
- Опубліковано 3 лют 2023
- Ensure you Like and Subscribe for more exciting Gamemaker content, or check out slyddar.com/ for more info.
Gamemaker has just released a new move_and_collide function, which allows you to program simple collisions in a very efficient way. You can have a platformer with slopes with a very small amount of code.
** What will I learn? **
In this overview I show how to implement collisions using this new function, and solve a few issues you might encounter when implementing it yourself.
Chapters
Sprites - 0:56
Objects - 2:02
Create Event - 2:53
Room Design 3:23
Step Event - 9:03
The First Platformer course mentioned in the video will be available shortly, but sign up to my mailing list below to be notified when it's released, and also to receive a special coupon code at launch.
NOTE: Patreon supporters can download the source code for this tutorial, and also watch any bonus content, over on the Patreon site - / slyddar
Also I am offering my Tile Based Moving Platform Engine for free, if you have donated at least $20 through Patreon. Contact me if you qualify for this offer.
Additionally, my Tile Based Moving Platform Engine is available at 25% off via this special link for viewers of my videos - slyddar.itch.io/gm-collisions
Keepers of Pyrite is currently a work in progress. To get the latest information, follow at / keepersofpyrite or check out the KoP channel in the Discord.
If you want to learn more GML, check out my Udemy course using the coupon code from my site, which will give almost 90% off.
How to make Tile Based Platform Games with Gamemaker Sudio 2 - Discounted Coupon Code - slyddar.com/2022/03/01/tile-b...
The trial version of Gamemaker Studio 2 can be used, and is available here - www.yoyogames.com/get
Join our community Discord - / discord
Follow me on Twitter for more Gamemaker content
Twitter - / slyddar
Facebook - / slyddar
If you want to be notified of my new content, or things related to Gamemaker, sign up to my newsletter - eepurl.com/dHBHyn
Gamemaker is made by Yoyo Games.
Thank you for the great tutorial. I also learned so much from your tile based platformer tutorial and though I didn't use it in the end because the lack of slopes, it taught me a lot of things that made me better at using game maker. Now this tutorial gives a really great base to platformers.
Great job resuming the new function ! First time on your channel, not the last :)
You're a really great teacher! Some things I like are also showing the visual code and walking through the failuresas well as going over basic stuff again like only using the 1st 3 arguments! It seemed really helpful and can probably help with a rotating platform that was giving me trouble! Thank you!!
Beautiful mate! Great tutorial!
thank you dude I kind of needed this. Keep it up
Oh my god it works, I felt like killing someone after trying to figure out stairs, failing to do so, and then I read that this feature was introduced, and couldn't understand how it works, and then I found this video. Thank you, you stopped me from some extreme actions )))
Great tutorial! \o/
Thank you very much
you can set the slope sprite to have a "rectangle with rotation" mask which i believe is much faster than precise collision
If you do that you will slide down the slopes when not moving.
Just wondering, but is there a way to add the drag variable from your previous tutorials onto the hsp?
the tutorial really starts at 9:30
Nice
Hey there! I followed along with the tutorial and generally everything works fine, but I noticed a small issue when rapidly shifting directions that causes the player to get stuck on the slope. Is there any fix to this?
This can happen if the movement speed is too slow, it's a caveat of the move and collide function itself.
I'm a beginner, how would i go about tiling this?
Question: does the new method work well with entity acceleration/deceleration?
I haven't added it here as I wanted to keep it simple, but it would be super easy, barely an inconvenience.
if(_right_key)
{
if(hspd_ < max_speed_)
{
hspd_ += accel_;
} else hspd_ = max_speed_;
}
if(_left_key)
{
if(hspd_ > -max_speed_)
{
hspd_ -= accel_;
} else hspd_ = -max_speed_;
}
How applicable is this code for top down, 8-directional movement?
Should work perfectly fine for it.
how would you handle slopes differently to normal tiles? want to make a system like jump king where slopes remove the ability to control the player and slide them in a certain direction
You could use instance_place to return the id of the solid you are on, and then use that to check if the image_angle of that solid is 0 it's flat, else it's a slope.
How to make one way platform with this?
my player is just falling straight through the floor. any help?
I show a screenshot of the code and it's only a screen high. Try pausing it and comparing mine to yours as you have something wrong somewhere.
because I've made the player go faster, how would i increase the clamp to a higher amount?
If you set move_spd to a higher value it should move quicker.
That video is AMAZING!!!! Quick question, if I change the variable move_spd to 5 or 6 the problem with the slopes start again (the player start jumping them) could you pls mention a solution for that pls!
Do you have an anwer or a suggestion for me?
When you add more speed, the 1 pixel we are checking below us to adhere to the slope will not be enough. You will need to increase that value to look more than 1 pixel below. Still leave the y += 1 though, but increase the place_meeting check value from 1 to 2, 3, 4, etc . You'll have to test values starting from 2 to see if it helps.
@@Slyddar problem totally solved!!! thanks SO much! all your videos are clear are helps a lot!
my player keeps randomly falls through the slopes....any ideas as to why?
player's got some jittery movement on the floor, tips on how to fix that?
Did you enable compatibility mode?
Could you make a tutorial on one-way platforms using this code?
Sounds like a cool idea, so... maybe :)
Hi! I can't find your new course on udemy.
Hi, thanks for the interest. Unfortunately I’m still finalising the course details on the Udemy site, but it should be available in early April though.
Hei ya! Thank you for this videos, i bought your tile based platform course on Udemy, i also checked your new one course but i didn't find it!
Hey thanks for the support! The new course is complete, but it's only the Visual section at the moment. I was waiting until I finish the GML section before releasing it, so a few more weeks unfortunately :(
@@Slyddar ok thank you, i will waiting
Wait, you're never setting the players x position variable. How does the player object even move without setting it?
move_and_collide applies the passed variables to the x and y position.
What about collisions with tiles? I don't use objects but tiles. What about that?
Move and collide is aimed at object collisions only. I haven't heard anything about them making it work for tiles too. I have a Udemy course which shows a great way to implement tile collisions, and make a complete game at the same time, if that interests you, but I also understand it's much more complex than this great function.
@@Slyddar Oh, I have also course on udemy with it, so thanks
How to realtime game for multiplayer
please write the code from the video in the comments, nothing works for me
Having some issues. When you hold a direction against a wall while jumping the sprite jitters and the jump height doubles. Can also get extra height if you graze against the side of a platform. I've tried this tutorial, and a few others and get the same results. I can mostly fix it but it starts getting more complicated than it should be. Should I just not use move_and_collide for slopes? Or am I missing something?
Edit: i switched to godot, problem solved :)
i like skibidi 😎😎😎
caraca tão difi´l ser programador hoje em dia
pricipalmente no game maker
Doesn't work. Player character just falls through all blocks.
Obviously it does work, as the video shows it working. It's more a question of where you went wrong.
@@Slyddar I copied your code and I'm having the same problem. So where do we look for fixing this problem?
Come to the discord and someone might be able to help you.
@@Slyddar posted
@@clayton_games And answered in the discord. For anyone else, hspeed and vspeed are not the same as hsp and vsp. Ensure you use the same variables and code I do otherwise it may not work.
idk what I do bad :(
#region plat_init
function plat_init(_maxspd,_acc,_desacc,_jmpspd,_grv,_maxvsp,_maxslope,_solid_par,_solid,_slope) {
//ex: plat_init(8,0.3,0.1,16,0.5,16);
maxhsp = _maxspd;
acc = _acc;
desacc = _desacc;
maxjump = -_jmpspd;
grv = _grv;
maxvsp = _maxvsp;
hsp = 0;
vsp = 0;
hsp_frac = 0;
dir = 0;
maxslope = _maxslope;
solid_par = _solid_par;
solid_obj = _solid;
slope_obj = _slope;
}
#endregion
#region plat mechanics
function plat_mechanics(_key_left,_key_right,_key_jump) {
var _move,_col,_frc,_mac;
_move = _key_right-_key_left;
_col = place_meeting(x,y+maxslope,solid_par);
//friction
if !place_free(x,y+1) { _frc = desacc; }
else { _frc = desacc/8; }
//calc movement
if (_move != 0) { hsp += _move*acc; }
else { hsp = median(hsp+_frc,0,hsp-_frc); }
vsp += grv;
//speed limits
hsp = median(-maxhsp,hsp,maxhsp);
vsp = min(vsp,maxvsp);
//jump
if (_key_jump) && !place_free(x,y+1) { vsp = maxjump; }
//adherir al suelo en bajadas
if (_col) && !place_meeting(x,y+maxslope,solid_obj) && (vsp > 0) {
while !place_meeting(x,y+1,slope_obj) { y++; }
}
//move and collide
_mac = move_and_collide(hsp,vsp,solid_par);
if ( array_length(_mac) != 0 ) && place_meeting(x,y+vsp,solid_par) { vsp = 0; }
}
#endregion
up the slope, but in final stops, and stops when try to down too.
if you happen to know how "not" to clamp to the nearest platform when jumping next to it, please add to this code too... it was the poorest code I ever seen!