GameMaker Studio 2: Action RPG Tutorial (Part 3: Tile Collision)

preview_player
Показать описание
(NOTE: right click and hit "save as" if this link appears not to work, it's a Chrome issue)

Learn to build a zelda like action RPG in GameMaker Studio 2, starting from nothing at all. This episode deals with colliding against a tilemap, a departure of sorts from the usual approach of colliding against object instances.

These tutorials are supported almost wholly by wonderful people via Patreon, click the link above to get join them an access these episodes early, get instant access to source code for all videos and more.
Рекомендации по теме
Комментарии
Автор

Scripts have changed! They now contain functions rather than being functions in their own right. When you create a script you will get a default function declaration. DO NOT DELETE THIS! Name it the same as your script and put your code *INSIDE* the function curly brackets.

SaraSpalding
Автор

that "congratulations on making it to episode 3" at the beginning really made my day

chris
Автор

20:30 Everyone: don't do it
Shaun editing: don't do it
Shaun while recording: so i made an oopsie

FelimSullivan
Автор

Just a tip for everyone, DON'T PUT A SEMICOLON AT THE END OF THE MACRO LINE! It took me nearly 2 hours of troubleshooting and reading forums before I saw that tiny mistake, fixed it then SUDDENLY it's all hunky dorey.

wfkmm
Автор

This is an old vid so IDK who'd see this but I got it to work. I did a few things tho. I found the issue was the game only thought that moving right/down set _collision to "true" and resetting speed to 0.

1. Make sure there are no semicolons after each line in the MACROS file.
2. The sPlayer and sPlayerRun sprites have identical sizes, origins, and collision meshes.
3. Follow the instructions in Shaun's pinned comment on scripts.
4. Change the brackets around a bit in playerCollision(). I used:

x -= mod TILE_SIZE; if(sign(hspeed == 1){ x += TILE_SIZE-1;} hspeed = 0; _collision = true;} x += hspeed

The difference being the hspeed = 0 and collision = true line are put in a different area. Use the same approach for vertical/y position code.

This took me like 2 hrs to figure out so if even 1 person saves time from this I'd be content.

asianbronyman
Автор

I just wanted to say I appreciate that you recognize the drop-off. Please keep up the good work, even with the lessoned support after each.

MrYeune
Автор

Hi Shaun! My son who's 8 yro and I love these tutorials. We're learning together how to make our first rpg game. Keep up with making these amazing material! 👏

pumpthegamer
Автор

I love that you make these tutorials fun by actually having a sense of humor as opposed to some other youtubers. Thanks for another helpful vid, learning a lot.

micaalexandermusic
Автор

For everyone following along up to this point make sure to include that "return _collision;" statement within the brackets of the playerCollision script! I just wasted an hour troubleshooting to realize I left it out, and it broke my screenshake feature.
As always, Thank you Shaun for all your hard work putting these up for us noobs :D

TheGrimmy
Автор

Attention: current version (v2023)!
For the correct vertical collision, the origins of the sprites must be set to "Origin 8 x 23"!

HerbieFirst
Автор

Im following through your tutorials for some months now and i had the most accomplishment that i learned something when this code doesnt work in my version of gamemaker but i managed to fix it myself. Thanks for being such a professor o/

juanmarcelo
Автор

For people having the glitch problem, be sur you have this: "if (sign(hSpeed) ==1)" and not this: if (sign(hSpeed ==1))
and same for "vSpeed"

at least it was the problem for me ;)

psirenvct
Автор

This has been up for a long time - but if you are running into the teleporting glitch, I found it was because of shaun's usage of the if statement syntax confusing me.
make sure it looks like this if you are used to using curly brackets with your if statements:
if (sign(h_speed) == 1) {
x += TILE_SIZE - 1;
}
h_speed = 0;
_collision = true;
NOT:
if (sign(h_speed) == 1) {
x += TILE_SIZE - 1;
h_speed = 0;
_collision = true;
}

TheXedMeister
Автор

I was struggling with making the collision function work with the current version (0.3.98) and after some troubleshooting I figured out that gamemaker doesn't like operations applied to macros in functions. My solution was to add in a var at the top and make it copy the value of TILE_SIZE. Below is what I have for my version of the function, results are identical, very little is changed from the video:

function PlayerCollision()
{
var _collision = false;
//Macros can't have operations applied to them in this version
var tilesize = TILE_SIZE;
//Horizontal
if (tilemap_get_at_pixel(collisionMap, x+hSpeed, y))
{
x -= x mod tilesize;
if (sign(hSpeed) == 1) x += tilesize - 1;
hSpeed = 0;
_collision = true;
}
x += hSpeed;

//Vertical
if (tilemap_get_at_pixel(collisionMap, x, y+vSpeed))
{
y -= y mod tilesize;
if (sign(vSpeed) == 1) y += tilesize - 1;
vSpeed = 0;
_collision = true;
}
y += vSpeed;
//Return state of collision flag when done
return _collision;
}

MAYOFORCE
Автор

All of your tutorials are great. Thank you for everything

The following are requests

(1) Tile collision for slope tiles
(Pixel perfect collision would be ideal, but slope tiles can be limited to 45 degrees)
(2) Wall sliding when colliding with tiles

toki
Автор

19:48 This is the exact reason why I decided to use the variable "ySpeed" instead of "vSpeed" cause I would make that mistake all the time

SquixHD
Автор

About the empty tile on the top left, it is because that is the eraser tile by default. This way you con use that spot as the eraser when painting on tiles.

Robzvideogamez
Автор

if you're having a problem where when moving right your character teleports over and over. add an if statement for the first line
if(sign(hSpeed == -1)){x -= x mod TILE_SIZE}

srspanksalot
Автор

Though I know this tutorial was made a while ago, for those if you having.. teleportation problems, Gamemaker has a built in property - hspeed. If you were autocompleting your own variable hSpeed, it may have autocompleted the lowercase built in hspeed instead. Double check your code to make sure you have hSpeed and not... hspeed.

MegaSimsie
Автор

I'm making it to episode 3 for the second time because i got distracted with trying stuff in a bunch of different game engines, your tutorial series are still some of the most useful tutorials i've had the pleasure of following :D

PocketDeerBoy