Good video! You can make the grid much faster with some simple edits though. Instead of : mp_grid_create(0, 0, room_width, room_height, room_width / gridsize, room_width / gridsize); You could use: mp_grid_create(0, 0, room_width / gridsize, room_height / gridsize, gridsize, gridsize); This will severely reduce the size of the grid and therefore up the performance. This does mean your grid will consist of even squares instead of being offset by the room width and height (which will happen if neither of the values are equal) That said, I can't really think of why you'd want unequal cells instead of perfect squares. EDIT: Realized I messed some initial calculations up and readjusted for that. This is why you proofread BEFORE sending the message lol.
I've got a problem, my o_player is 64x64 px, and my o_solid is 64x64 px, and no matter what i put in cellwidth and cellheight in mp_grid_create, my player clips into a wall and even walks in paths that he can't fit (where path is 32px width only or even 16), any idea why this could happen?
I'm not sure, no. It sounds like you're got fairly regular art assets, so it must be something with the code. Check out my source code from the description, and see if you've done anything differently. You could also try importing your sprites into my finished projects, to make sure it's not them.
thank you for your response! i downloaded your already finished project and triend to do similiar thing with your assets, and player can walk right up the wall. Here a screenshot with red dot as origin point of the objPlayer imgur.com/a/zdrNA. And side note, in objGrid in the create event, mp_grid_create hcells and vcells shouldn't equal to room_width and room_height, because you're getting the 640 and 480 cells that are going past the screen and that's why fps heavily drops, I used in your project room_width/32 and room_height/16, fps = 1000+
Instead of declaring each individual object as an obstacle, could you have all of your objects be children of a parent object, and then just declare the parent object as an obstacle? That way you could add new objects to the room without having to go and declare it in the code?
this works for me to a point. if i add more then one object to the grid the character doesnt move at all. if only one object is added then it doesnt work. Game Maker Studio 2 v2.2.2.413
Hi, in my project I want the A.I. to move on a grid. In chunks of 8 pixels (this may change to 16 in the future, I doubt it matters). And I don't want the A.I. to move diagonally. I have no clue how to do this and help would be great.
A.I. movement on a grid is a pretty big process. What I'd suggest is making sure you understand this, and then look into the grids data structure. My idea is to combine the two, having each cell in the DS grid represent a movement space in your game, and then filling those in based on the grid you've created in your map. That's just the first idea that comes to mind, I'll think on it more.
Hello, i have a question, when i do the exact same my unit doesnt move to the center of a new grid cell, how do i make it so it does? I have when i click some where the mouse_x becomes destinaitonx and same for the y, do i need to change this to something else?
@@LetsLearnThisTogether It goes to the exact point i clicked, so where my mouse was. But in the video and what i want is that it goes to the center of the grid cell. I guess that is defined in your guard when you clicksomewhere, but i cant find the video where you did that.
Hmm. I do believe there is a function to find the nearest grid x and y, so if you have the mouse x and y coordinates, you should be able to use those to get at what you want. I’m not sure which video it is where I do that though.
Hi, can you explain. Let's imagine on soil player's spd is 2 for example, on road 3. How I can teach him to search way on road and use it, and what about doors in rooms using path how to
Howdy. There are several ways to accomplish this, but the first that comes to mind is to lay down an invisible road object that the player checks to see if they're colliding with. If they are, change their speed to that roads speed. Other ways would be to check the sprites of the background, if you have that set up.
would it be correct? set to road collide with player add spd += 2 create path for player from A to B check ich sec nearest road if find, create another path from player to road check nearest place from road to B create path on road to nearest place B check who faster path from player to B or from road to B choose right way and go for house we want to create path from pleayer to locked room (remember position in house) check this is house or just a wall if house find door create path from player to door move player use door, create another path from player near open door to position in house sorry for my English =\
Something like that yeah. Although you'll probably need to be using collision checking functions, instead of the collision event, as that normally stops two things from colliding.
Pardon me. I am attempting to use this type of grid movement, but my character is ignoring the added instances, and is walking through them. Is there a way I could get help for this?
@@techiemay It's been a while since I have done anything with this, either. If you're adding it to the grid successfully, then check the sizing of it, if it needs to be solid or not, and the collision mask.
Let's Learn This Together what does solidity have to do with it? I’ve run the game a few times with solidity on and off and didn’t know if it mattered. Do they need to be in the room when they are added to the grid? They spawn in a few frames after the object is added to the grid.
I’m not sure if Solidarity is important, as I haven’t played with grids in a while. If you export or zip up your project and link it here or email it to me, I’ll check it out.