#Collision problems with Make Your First RPG

85 messages · Page 1 of 1 (latest)

ornate iron
#

I'm following along with the Make Your First RPG tutorial on youtube, and so far it's going great, but the collision code isn't working.
I'm having problems in this section of the video: https://youtu.be/1J5EydrnIPs?si=tiR8mGaaVVjGvUeE&t=568
My code looks like this:
Under create, I have

move_speed = 1;

tilemap = layer_tilemap_get_id("Tiles_Col");

and Under step, I have

var _hor = keyboard_check(ord("D")) - keyboard_check(ord("A"));
var _ver = keyboard_check(ord("S")) - keyboard_check(ord("W"));

move_and_collide(_hor * move_speed, _ver * move_speed, tilemap);

The only thing that comes to mind is that I don't have an object for the tiles I'm trying to make the player collide with, but that shouldn't matter when using a tile set, and having all the tiles I want to collide with the player be on one layer, with the others on a different layer. This system worked for the developer in the tutorial, but not for me. Making the player object solid has not fixed it either. As far as I can tell, I haven't done anything different from the tutorial, and everything else is working as intended. Please let me know what could fix it.

Create your own Role-Playing Game (RPG) in GameMaker 👾. These tutorials are designed to take you from beginner to completing your first game step-by-step. No coding experience is required.

👉 Get GameMaker (it's 100% free): https://opr.as/DownloadGM-YT

00:00 Intro
00:46 Create Your Project
02:29 Level Design
07:12 Player Movement
11:50 Pl...

▶ Play video
chrome grove
#

Does the sprite assigned to the tile set for the Tiles_Col layer in the room have a collision mask set up for it?

#

What happens currently? I'm assuming movement and no collision at all, just walking right through the collision layer tiles.

#

Similarly, does your player object's sprite have a collision mask set up?

#

If there's an issue with your code, I am missing it. But there's setup which needs to take place with the assets themselves in order for the collision to occur.

#

If your collision tile set is just a square the size of a tile, then you can just set it up with basic collision. If you have different shapes and such, then you need to set up precise collision.

ornate iron
#

Tomorrow, when I’m not exhausted.

ornate iron
#

Ok so yeah, the collision mask for the player is set up. I don't know how to set up collision for the tile set though.

#

Though looking at recent videos, it looks like I shouldn't have to set up collisions... Cuz the guy in the video didn't have to.

#

The only notable difference is that he's on code editor 2 beta, and I don't know how to enable that. But it doesn't look like that changes a whole lot other than formatting.

#

Going into the sprite for the tileset, a collission mask IS set up.

#

So I have no clue what's going on.

#

Yeah I'm stuck.

chrome grove
#

I'll take another look at the code, but I'm not seeing anything wrong in the code.

Could you take a screenshot of the layers that exist within the room and post that? Or you can send me the project and I'd be happy to take a look.

ornate iron
#

Let me just send the project file.

chrome grove
#

Sure.

#

You can export a YYZ of it. Generally the best way.

ornate iron
chrome grove
#

File > Export > YYZ ?

ornate iron
#

let me see

chrome grove
#

Sorry, File > Export Project

#

And one of the options there would be YYZ.

ornate iron
#

Oh I see

chrome grove
#

So... sadly I haven't figured out what specifically is making your setup not work, but I created a new tile set, sprite, and layer. And then just swapped in that new layer name into your get ID, and it works. So no issues with the code.

ornate iron
#

Oh, huh.

chrome grove
ornate iron
#

That's confusing. Not sure why it refuses to work otherwise.

chrome grove
#

I'm not entirely sure either. There really isn't a lot required to set it up. Tile set needs a sprite with a collision mask. Assign sprite to tile set. Add layer to room. Get the ID using the layer name as a string.

I drew your "tilemap" variable to the screen, and I can see that its getting the tilemap reference, so... weird. I'm sure I'll find it eventually. But for expediency's sake you may want to just make a new sprite, tileset, and layer and swap it out. See if it works.

#

Since that is maybe 5 minutes of work.

ornate iron
#

Alright. I'm not used to making tile maps, but I'll see if I can figure it out. Shouldn't be too hard.

chrome grove
#

So... seems like there might be an issue specifically with the sprite. If I use my sprite it works. If I use the sprite you had it doesn't.

I'm not entirely sure why. For my project, the collision layer is just a semi-transparent red shape that I draw on top of the normal tile set which I set the game to not draw during runtime.

#

And I've never had to do more than draw in those shapes and make sure that the collision mask was set up.

ornate iron
#

huh.

#

Yeah this issue is certainly getting on my nerves, ha.

chrome grove
#

I can see why.

ornate iron
#

Any chance you can just send me the file for the version that works, and I can continue the tutorial from there?

chrome grove
#

For whatever reason I literally can't get the tile collision to work when I use the provided sprite. Even if I set the collision mask to be the full image of the sprite. What I probably can do is set you up a separate layer which uses a different tileset with a different sprite? One which is invisible when you run the game. So you just draw with it on top of the walls.

#

Code wise nothing would change.

ornate iron
#

Yeah, we can try that.

chrome grove
#

Gimme a sec. Should be able to do that.

ornate iron
#

Thank you

chrome grove
ornate iron
#

Thanks!

chrome grove
#

I added a new sprite, a new tile set, and swapped that tile set in for the tileset used by your collision layer.

I also added a Room Start event to your player object which makes that layer invisible. So you can just draw your walls on your normal non-collision layer and then paint collision wherever you need it.

#

That's how I usually do it.

#

I'm sorry I can't tell you why the provided sprite isn't working, lol. I even exported the image and added it as a new sprite... still didn't work.

#

Baffled.

#

Also a better way to do it, just generally, since you can actually tell where there is and isn't collision in the editor. Whereas the way he did it you cannot visually tell the difference between the two layers.

ornate iron
#

ah

#

Well, where's the sprite you added? I still keep walking through walls...

chrome grove
#

...Did I not save?

#

One moment!

ornate iron
#

I mean the red transparent tileset is still there.

chrome grove
#

So you can see the red transparent tiles in the editor?

#

You would put those on top of the walls.

ornate iron
#

Yeah that's what I did.

#

I can walk through them.

chrome grove
#

...Not where I'm sitting, you can't.

ornate iron
#

Uh let me remove the code that changes the sprite.

#

or comment it out

#

Uhh yeah I have no idea what's going on.

chrome grove
#

I'm just going to save and re-export just to make sure I didn't forget to mash save.

ornate iron
#

ok

chrome grove
#

Here's what the collision layer should look like in the editor on that.

ornate iron
#

Yeah I mean that sure is what it looked like... I think the problem might be on my end.

#

My version might be bugged or something.

chrome grove
#

To be clear, when you opened the YYZ you allowed it to make a new project using the YYZ, yeah?

ornate iron
#

Yeah

chrome grove
#

And then opened that?

ornate iron
#

Yep. I'm gonna lose my marbles

chrome grove
#

I should be on the newest version of the non-test IDE. If you want to make sure you are updated. Though, frankly, I doubt it matters.

ornate iron
#

I'm on LTS, forget which version. It's weird, since everything else works as normal.

#

Lol, I thought this would just me a simple one word answer thing, like I forgot a semicolon or something. NOPE.

#

I might give up for today since it isn't making any sense. I did start the spacerocks tutorial so I'll probably do that for the time being.

chrome grove
#

Okay. Fair enough. That's generally a better starting point. Though I'm not seeing anything you did wrong.

#

And I have no idea why the version which I fixed would not work on your machine but would work on mine.

ornate iron
#

Yeah me neither. I'm stumped. If anything, I might start from scratch with my own sprites and tilesets, and see if that works. But I'm not gonna do that right now, because I'm at my limit.

chrome grove
#

Understood. Always good to take a step back when you get frustrated.

#

My recommendation for when and if you want to give it another try with your own assets. Start off with a blue square for your player, red tiles for your collision layer. When you get everything working the way you want it, just set up that layer to be invisible and then swap your player sprite with non-placeholder assets when you have them.

#

Don't even worry about a background. Background is just a drawing.