This is like when Harry learned he was a wizard. I can't believe how easy this was, I feel so powerful. 15 minutes to implement a massive improvement to my game. Absolute legend, thanks for making these videos.
If you can start flying on a broom give me a call. I would like to do that too and then I can call you legend for real :D. But besides banter, glad I could be of service.
I'm creating the game Corpsenia. If it works, know that you helped me a lot! The pathfinding mechanic was essential. Thanks! If I succeed I will teach everything I know I learned too!
Glad to hear I could help you out here and thanks for watching! If you got a demo or something to share plus you want to see cloud drop me link or key, so my community can have a look at your game.
Hey indie you wouldn’t happen to have a video on field of view would you? Trying to make it so when an enemy sees you they switch states to chase. I was gonna use an object cone as a fov but I don’t like the idea of it going through objects and seeing you on the other side.
Well sir, you may be in luck. I did a cone of sight in my remake hotline Miami in GameMaker series. ruclips.net/video/4qt7uFX9T-8/видео.html Was that what you are looking for?
These videos are cool and useful But I wanted to know can you make it so the enemies collide. I tried my hand on it for a while but couldn't get it because I'm understanding this right I would have to make the grid again every time an enemy moved. Can you help, thanks
Well, what you are looking for are anti-cluster/anti-overlap algos which are called "steering behaviors", which this method does not provide. Refreshing the grid constantly is needlessly resource intensive. I have seen some A* solutions, so that may be a way to find this. Or try the solution provided in this forum (OneExalted): forum.gamemaker.io/index.php?threads/keeping-enemies-from-touching.29105/ forum.gamemaker.io/index.php?threads/steering-behaviours-the-ai-system-everyone-needs-for-their-game.23370/ Hope that helps!
Just found this 3 part series and holy crap it is amazing. I am making a zombie game with a maze, and couldn't figure out how to make path finding work. I was using mp_potential_step_object, but I realized it wasn't working correctly because I had a maze. I couldn't figure it out until I found this 3 part series! Thank you!
Ehm, I didn't do a 4th video because that pathway system is pretty cool out of the box but it has limitations. So that is the most you can get out of it. You mean like flying towards you? Then you can simply have a Vampire Survivors style gameplay. I did a video series on that: ruclips.net/video/QxL9jjNSz98/видео.html Or if you have not many enemy flying then you can simply put in their step event (your player coordinates and theirs) -> direction = point_direction(x,y, obj_Player.x, obj_Player.y); speed = 1; or move_towards_point(obj_Player.x, obj_Player.y, 1); What that what you were looking for?
This is really good and exactly what I needed for my game. I had a question though, the thing I'm trying to go around moves which causes the character to sometimes go through the wall instead of around it. I tried making it run every step of the game but it still seems to go inside the walls. Was wondering if you know how to fix this. Just additional info the thing I'm trying to get around is a big sprite that needs to be precise but moves extremely slowly.
I assume you are talking about moving platforms, which causes the enemies/npc/player to glitch into walls? Well, in that case you would need to refresh (the whole wall instance setup, not recommended) quite a lot which is taking a lot of computation. This method works pretty good if you have a static (one time set setup) which stores one in memory where walls and free space is. And by moving a platform you create glitchíng. To remedy this you would need to create your own A* algorythm that takes moving things into account which, is not easy to do.
Hello, i was just wondering on how you did the animations for your enemies? I've been trying to figure out how to turn my enemies as they move along the paths and i can't figure it out.
You mean the actual sprites inside the object? Or the state machine (idle/walk). I guess you are refering to the flipping towards left or right? In that case I simple invert the image_xscale, 1 for going right and -1 for going left. So you need to check the xprevious and x (current value), this decides how the image is flipped. Was that what you were looking for?
Man, this video helped me a lot, I cannot thank you enough. However I hava a doubt about a thing I want to make a little different of whats on the video, but I don't know how to do it. I want the "x" and "y" of the path to be random number from the created grid. Do you have any idea how can I do that, if its possible?
@@1upIndie I want the code to return me a random x and y position, based on the grid. The grid covers my entire room and it's size is divisible by 16, wich is the cell width and height that I set up on the grid. I'm a begginer in programing so I apologize for my cofused logic, but I thought that obtaining a random position from the grid area would be better because the grid area already excludes any position of placed instances of "obj_walls" in my room.
I was worried that if I use a random function to get random coordinates from the room itself instead of the grid, if I try to use a path that is grid based is possible that the random coordinate can't be reached by the grid movement.
Yes, in that case you check what kind of direction the enemy/instances go. So you read it out and flip the image_xscale accordingly. Something like that: if (direction >0 and direction < 90){ image_xscale = 1; } if (direction >= 90 and direction < 270){ image_xscale = -1; } if (direction >270 and direction < 360){ image_xscale = 1; } Hope that helped!
@@1upIndie i asked the question wrong, im trying to do a pac man clone and ive been trying to find a way to check for the closest next point on the path They wont do diagonal movement, my logic is if the next point in the path is postive X, they will still look at that direction until it changes to another closest point problem is i have only 3 brain cells and cant figure a way to do that
Thank you for this i video! It's really helpfully :) . i want to ask you a question: if we have more than fifty "enemy" how can we improve the code? Simply by changing path alarm time to 1 or 2 seconds?
Well, you can marginally improve the code, so things like things like update lowering or doing a lot of code from one source (instead of all of them) can help this. But if you really want large numbers of enemies on the screen, then this system is not what you are looking for. It is meant for lower counts (50-100) enemies where they can go complext paths.
Hello, ty for this good tutorial! I'm looking for how to use it with bigger monster but same wall size. (Exemple: enemy size 64x64 but wall 32x32) If you have any advice for the collision to avoid that a part of the enemy cross the wall.
Acually yes, you simply assign a different collision mask (below where you assing the sprite) that is small enough instead of the default one that is being used when you assing a sprite to the instance of the enemy.
@@abesses6630 Hm, if you need some help, maybe go into my discord under the "help" section, there are always some guys that do help out new developers.
This method changed the direction where you are goind and I set therefor the sprite according to the newly set direction. But that would look somestimes a bit twichy, so I update that sprite swap with an alarm event that updates around each 30 steps (half a second). Was that what you were looking for?
@@1upIndie Coudl you also include in this video how to check if enemy is seeing player please? Im making a game where enemies are shooting, and i want them to not shoot if they dont see player.
Not sure what you mean by room. If you swap through rooms (aka, another level) you simply repeat the process like shown here. Or do you want to have enemies go from one room to the other with the player?
Liked, subscribed. Question. In my game if enemy has less than 10% hp, it is supposed to run away from the player, and i want to make it so that it runs using pathfinding, but I dont know how to do it. If you can pls give me some advice.
Hm, what you can do is to go radially around the player (or rather a cone). 1st You would need to get the direction from the player to the enemy (aways from him). 2nd I would make a random difference from that direction (this is then a cone of possible directions where to go). I would say around +- 25 degrees 3rd so use lengh_dir from the player to get the specific new direction 4th check if if that spot is free (no wall there), if all good apply this new positon for the enemy to flee, if not start again with the 2nd step. Hope that helps!
This is a longshot, but is there a function in gamemaker that lets you use the path system with tilemaps instead of a collision object? I just switched to using tilemap collisions with my player but quickly realised that mp_grid_add_instances doesn't support tilemap id's, I'm hoping there might be a fix out there that supports this kind of system?
Hm, interesting. I would need to check if that is possible since they (as you stated correctly) added tilemaps aswell to the mix or they will add that in the future.
Thank you for the amazing tutorial as always! So, this is a specific question but, I am making a game that has randomly generated maps, including obsticals. Will it matter where I put the NPC's? The whole gimmick of my game is randomization
Sure, if you do randomization you need to have a spawn controller where you spawn enemies. After the random maps are finished and check if on that random spot you can place an enemy with a collision check. If no collision is there this spot is free and you can save this in an array or instantly spawn an enemy there. Was that helpful?
@@1upIndie I understand yeah! So I'd just have to make the enemy AI check the map after it generates, right? I was thinking I could also create a clear area where the enemies spawn with no obsticals, then have them calculate from there
@@1upIndie just to insure I do it right, would you mind writing the first bits of the code? I'm not familiar with arrays, other than that they are essentially a list of information
@@hothead1546 That is possible also, to have "free" spots where all your generated maps don't place obsticles/walls etc. . The video here does have one start assigment part where your obsticles are being marked as unpassable so that the enemies can create paths around them. So it makes sense to have an order or creation: 1. generate map with walls/obsticles 2. do the grid setup like in the video once 3. create enemies where they can be placed
@@hothead1546 I assume you are new to programming (which is totally fine, you get quickly lost in the vast amount of tutorials etc.), so familiarise yourself with the boring basics, because you try to do out of the box advanced coding which will very likly frustrate you. I write that because this cannot be simply achieved with a few lines of code. Come in my discord and let's see what we can do here.
Well, that is much more complicated. You would need to ditch this "ready to use" system shown in the video and create your own pathfinding A* algo plus an anti clustering vector collission system.
@@zarc677 I have not found any to be honest. All the vampire survivor games use build in collision systems (Godot, Unity, Unreal) which take care of that. GameMaker has none and so you have to build your own. I haven't found a solution that doesn't tank performance.
let's say for example I had obj_player run an instance_destroy command when it touches the zombies. When I do this, the game crashes for me. I even made sure to put in a "if instance_exists" statement and it still crashes. I think it's because they're seeking the player's position rather than the exact coordinates. I'm not too sure, though. Any help would be appreciated. Very helpful video, though. You have my thanks!
You are correct in your assement here, the code looped in the alarm is getting the x,y value of the player instance, if it is not there (gamemaker cannot get values out of no existent references/data) the game crashes. Technically it makes no difference if you give some fixed x,y coordinates to search for or current player one's (it should not crash) and check if it exists. What you could is to create a player_Parent object and have 2 children (check out inheritance if you are not sure about it). The obj_player itself and a obj_dummy. The dummy is being spawned when you destroy the player on the same spot (when you destroy it). So you have in the search code then target_x = obj_Player_parent.x; target_y = obj_Player_parent.y; instead of the "old" code. You always have then a target coordinate That should fix the issue. Hope that helps! Video on inheritance/parent child objects: ruclips.net/video/ytoWx081WWk/видео.html
@@1upIndie Thank you sir. That's helps a lot with the player issue. You have my subscription. However, I have allies in the game that shoot at obj_enemy_parent and use the same path-finding scripts to get to them. This creates a similar, if not the same, issue, when they shoot the enemy and the enemy instance is destroyed. Even though there are other instances of obj_enemy_parent for them to seek out. It seems that the instance they're following get's destroyed before the path can update and seek another instance. I assume this is true, because the game randomly works fine and randomly crashes with a similar error message. Edit: For some reason the game didn't like me using variables. Now instead of target_x = target.x and setting target.x to an instance_nearest command, I just set it as target_x = instance_nearest(x,y,obj).x. Idk why I couldn't have just used a simple variable. It crashes a lot less now for some reason. And congrats to you for keeping up with a 2 year old video. Someone with as much dedication at that deserves more subs.
@@LuthersLounge Thanks for the trust in subbing. Hm, I wonder why the game is being unstable because normally it works or it instantly crashes (normal experience for the last 5 years with GameMaker). Variables are pretty set in stone, either you declare them in the create even for further use or have temporary ones (var keyword) and can use them only in that event where thery are being declared. So it can be the engine (contact the offical YoYo help desk, it always has been not good on mac devices in the past) or code that does work wonky at times. If you are unsure, maybe use the offical GameMaker or my personal discord channel and ask for help there. You can better answers there then me doing guess work (which sometime does help though).
idk where but ive also purchased this tileset/asset pack before with the zombies, character icons, buildings, cards, roads, etc. if you remember/know what its called please let me know cause i would buy it again in a heartbeat
Sorry, but I have no idea how to help you here. To have an allround system you would need to swap between the pathfinding and an additional instance control system of your own.
Hm, did you try drawing you collision masks and see if that is the root of your issues? In your draw event: draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom,1); Was that helpful?
@@1upIndie i did draw the collision masks for both my enemy and collision blocks, both are working as intended but my enemy's collision mask is clearly going into into the block
nice video but get this I found out on certain dimensions the boxes are not equal l.(in different sizes)) grid = mp_grid_create(0,0,room_width/32,room_height/32,32,32) and so like some dimensions work so what's the issue
what if i want the objectto go around multiple objects? I have my normal solids but i also have a moving solid, and i dont want the enemy to go through that either. what do i have to do to prevent that from happening? also: im trying to use a random spawning system with the solids and now it doesnt work anymore. why?
Well, that is a bit more tricky since you "map" with the setup once where solids are and the inbuild A* search algorythm does create possible routes for each enemy via paths. But now you want to go from a once setup static setup to a dynamically updated one. So, you can do the setup phase each step which will take a toll on performance or you can create your own custom collision/route system which is possible but not an easy solution.
My only problem with this code is that all the NPCs are rubbing against the walls when trying to follow me. it looks very weird. any ideas on how to fix this?
I just tried your code, but it's not working, the whole path part. It's not drawing a path and the instances aren't moving at all (but the mp_grid seems to be working just fine), I wonder if these funcitons got broken by some GM update?
Hm, GameMaker updates have a tendency do break things, so it is not out of the possible realm. Sometimes flushing the cache (clean symbol next to start icon) may solve your issue. If not, try the offical yoyo or my discord server and ask for help there. I cannot really help you in such a situation.
One question how can i use this when i have no room size defined? Like my room is 1 by 1 pixel big but due to a custom camera i can go anywhere i dont thik its a good idear to make a grid that is 100s of thousands of sqares big.
Technically you can have a grid of one pixel, but will become memory intensive. So it maybe would be better to have "bigger" squares so that the algorythm is less taxing and set the grid only on the area where you want it it be (video goes for the full room).
@@boxedgamedev9462 You could update it, but the more you do that the more it will tax your performance. Just play around with values and condition until you find a good solution to your current project.
Not necessary but it gives a programmer that is new in GameMaker context what is possible. The method in this 3rd video of this series is the most "complex" one and maybe not what is needed for your game.
Hm, then this is maybe not what you are looking for. This is system is for dynamically guiding instances (heavier on cpu) around tricky obsticles. For a linear/fixed apporach/ways/road I would use the path system.
Hm, not sure I can help you out without seeing your project (I cannot, I get too many requests for help). Did you try my discord help section? Maybe somebody has the same issue or knows how to fix your problem.
I don't get it you create the purple enemy grid but it moves the ennemy don't understand why , when I try to do it, it lag so much it doesn't work and nothing happen.
No estoy seguro de cuál es tu problema. Pones todas las cosas en la habitación. Si desea hacer que las paredes u otras cosas sean invisibles, puede hacer clic en el objeto "visible" o en el evento "crear" visible = false; escribir ¿Fue útil?
Can't get it to work. Everytime a path is created the game crashes and gets a checksum error. Wondering it might conflict w the rollback multiplayer features. hm
I am not sure how I can help you here plus I haven't done anything network related (checksum is a not readable/not closed network data) with GameMaker.
I have a question when I run the game my enemies start moving but once the path gets updated they stop in one place and don't move at all do you have any idea how to fix it?
Dunno, check the "speed" variable ( i would draw_text it above the enemy). I guess your issue is that they are not running in a new path (so you are maybe not updating or something is missing to "kickstart" the new movement).
@@1upIndie Yeah speed was the problem I don't know why but in the path_start event when I was typing the built speed variable as speed it wasn't working but when I typed the exact value it worked, so thanks a lot
That doesn't work with this system (it is boxed and not meant for this), you need a your own custom A* search algo with anti cluster algo, which is not beginner friendly.
Well, you have the bounding box the instance to be bigger or same size as the Sprite or you draw the walls over the image (walls layer is on top of your sprites layer.
@@Infernoplex Yes, that but you see my enemies are those red/pink rectangles (sprite index). Here I simple do a "fake" draw event above the draw self, so that you can the see the box/rectangle which does the collisions/pathfinding and then the good looking sprite above it.
@@1upIndie Hi, I've gone through the vids again from 26 to 30. All of your examples involve a single player and enemy, so the lining up/grouping behaviour is never actually seen, and subsequently I don't see anything in the code that would negate it. You certainly don't draw any attention to it. It's got more mechanics, like the line of sight, etc, but I'm not seeing anything that specifically would prevent multiple enemies converging. I do have a solution that I'm trying to impliment in my own game, but I was really interested to see what yours would be, mostly to see if it was a more elegant sotution.
@@0ADNewbieRush I didn't implement any grouping/clustering code because the series was ended. There were a few more systems I originally wanted (patrolling, grouping, calling for reinforcements, stunlocks from the player etc.) to do but since view counts and watch time were abysmal I had to cancel in the end. 26-30 Were "only" doing a state machine that goes, follows and shoots. All necessary basic moves. I don't intend to futher the series or add more mechanics, so in that regard that is pretty much the end. There is a good video on that, maybe that helps you out: ruclips.net/video/OmnUZM4-B6o/видео.html
If you make it so the enemies trail the pathfinder object loosley, you can get some very cool effects where it isn't as clustered. anyone have any good tips for getting them to avoid one another?
@@1upIndie I ran some updates as well to make it so that every update, it updates the navigation mesh to include pathfinder, so they have more boyd like behavior
Just a note, when 1up indie says it takes alot of perfomance, hes not joking. With my game the rooms are huge, 50,000 by 50,000 and i get a game crash error where gamemaker runs out of memory, when trying to draw the grid!
Hi. I have an error, really weird one. U see, im using grid = mp_grid_create(0,0,room_height/64,room_width/64,64,64); (because i operate on 64x64 sprites) but this makes my grid draw... only half on the screen, left to be specific. But when i change room_height and width to room_height/32,room_width/32, grid draws normally (but works not as i intended) what the hell actually? ibb co/KF7Q3kX (this is how it looks like when i changed room size to x2 ibb co/0tVwZ41 this is oryginal room size put a dot between ibb and co cuz youtube deletes links ._.
This is like when Harry learned he was a wizard. I can't believe how easy this was, I feel so powerful. 15 minutes to implement a massive improvement to my game. Absolute legend, thanks for making these videos.
If you can start flying on a broom give me a call. I would like to do that too and then I can call you legend for real :D. But besides banter, glad I could be of service.
Truly the best tutorials. Straight to the point, very well explained. Thanks so much!
Thanks for the trust (and actually subscribing!) and watching my content.
You do not know how much this helped me
I used a different tutorial and for some reason it was really broken
Thanks
Glad to know I could help a fellow developer out!
I'm creating the game Corpsenia. If it works, know that you helped me a lot! The pathfinding mechanic was essential. Thanks! If I succeed I will teach everything I know I learned too!
Glad to hear I could help you out here and thanks for watching! If you got a demo or something to share plus you want to see cloud drop me link or key, so my community can have a look at your game.
Hey indie you wouldn’t happen to have a video on field of view would you? Trying to make it so when an enemy sees you they switch states to chase. I was gonna use an object cone as a fov but I don’t like the idea of it going through objects and seeing you on the other side.
Well sir, you may be in luck. I did a cone of sight in my remake hotline Miami in GameMaker series. ruclips.net/video/4qt7uFX9T-8/видео.html
Was that what you are looking for?
@@1upIndie ooooh awesome I think that might be exactly what I am looking for thank you!
These videos are cool and useful But I wanted to know can you make it so the enemies collide. I tried my hand on it for a while but couldn't get it because I'm understanding this right I would have to make the grid again every time an enemy moved. Can you help, thanks
Well, what you are looking for are anti-cluster/anti-overlap algos which are called "steering behaviors", which this method does not provide. Refreshing the grid constantly is needlessly resource intensive. I have seen some A* solutions, so that may be a way to find this.
Or try the solution provided in this forum (OneExalted):
forum.gamemaker.io/index.php?threads/keeping-enemies-from-touching.29105/
forum.gamemaker.io/index.php?threads/steering-behaviours-the-ai-system-everyone-needs-for-their-game.23370/
Hope that helps!
Awesome tutorial, I’m going to see if I can reverse engineer this to create a patrol , chase, and return to initial point function. Wish me luck.
Well, you can use it for all. For partrol I would manually set a path, I guess this one would be cleaner.
I’ll keep that in mind. Thank you.
Patrol is a good idea.
Good luck! :)
Just found this 3 part series and holy crap it is amazing. I am making a zombie game with a maze, and couldn't figure out how to make path finding work. I was using mp_potential_step_object, but I realized it wasn't working correctly because I had a maze. I couldn't figure it out until I found this 3 part series! Thank you!
Sweet, good to know my stuff helps some people out.
amazing tutorial, thanks
Thanks for watching!
this is really cool
your vids deserve way more views than they have dude. super informative!
Thanks, that would be great.
I agree with you, he is one of the best teachers on RUclips. No unnecessary info, just straight to the point, effective code!
You are the best 1up!!!
@1upIndie Did you ever make a path 4? I want to learn how to make them not collide when chasing
Ehm, I didn't do a 4th video because that pathway system is pretty cool out of the box but it has limitations. So that is the most you can get out of it.
You mean like flying towards you? Then you can simply have a Vampire Survivors style gameplay. I did a video series on that: ruclips.net/video/QxL9jjNSz98/видео.html
Or if you have not many enemy flying then you can simply put in their step event (your player coordinates and theirs) -> direction = point_direction(x,y, obj_Player.x, obj_Player.y); speed = 1; or move_towards_point(obj_Player.x, obj_Player.y, 1);
What that what you were looking for?
That was awesome !! love it
Thanks for watching!
Muy bueno, aprendí algo que de chico siempre quise hacer en mis juegos. Ya quiero ver el Hotline Series
Pues diviértete con la serie hotline
This is really good and exactly what I needed for my game. I had a question though, the thing I'm trying to go around moves which causes the character to sometimes go through the wall instead of around it. I tried making it run every step of the game but it still seems to go inside the walls. Was wondering if you know how to fix this. Just additional info the thing I'm trying to get around is a big sprite that needs to be precise but moves extremely slowly.
I assume you are talking about moving platforms, which causes the enemies/npc/player to glitch into walls? Well, in that case you would need to refresh (the whole wall instance setup, not recommended) quite a lot which is taking a lot of computation. This method works pretty good if you have a static (one time set setup) which stores one in memory where walls and free space is. And by moving a platform you create glitchíng.
To remedy this you would need to create your own A* algorythm that takes moving things into account which, is not easy to do.
Hello, i was just wondering on how you did the animations for your enemies? I've been trying to figure out how to turn my enemies as they move along the paths and i can't figure it out.
You mean the actual sprites inside the object? Or the state machine (idle/walk). I guess you are refering to the flipping towards left or right? In that case I simple invert the image_xscale, 1 for going right and -1 for going left. So you need to check the xprevious and x (current value), this decides how the image is flipped. Was that what you were looking for?
You rock man!! God Bless
You are welcome mate!
you are a boss, greetings from Argentina
Thanks a lot! How is your country doing right now if I may ask? Argentina was once 3rd richest country in the world and could go back to that.
Man, this video helped me a lot, I cannot thank you enough. However I hava a doubt about a thing I want to make a little different of whats on the video, but I don't know how to do it. I want the "x" and "y" of the path to be random number from the created grid. Do you have any idea how can I do that, if its possible?
Not sure I can follow your thought pattern. What do you mean by random x,y of the path?
@@1upIndie I want the code to return me a random x and y position, based on the grid. The grid covers my entire room and it's size is divisible by 16, wich is the cell width and height that I set up on the grid. I'm a begginer in programing so I apologize for my cofused logic, but I thought that obtaining a random position from the grid area would be better because the grid area already excludes any position of placed instances of "obj_walls" in my room.
I was worried that if I use a random function to get random coordinates from the room itself instead of the grid, if I try to use a path that is grid based is possible that the random coordinate can't be reached by the grid movement.
Great tutorial my guy!!!
You are as always welcome mate!
Thank you, very helpful.
Ah, thanks for the trust that my content is useful to you.
hey man, do you know how to make the sprite change to fit its direction?
Yes, in that case you check what kind of direction the enemy/instances go. So you read it out and flip the image_xscale accordingly.
Something like that:
if (direction >0 and direction < 90){ image_xscale = 1; }
if (direction >= 90 and direction < 270){ image_xscale = -1; }
if (direction >270 and direction < 360){ image_xscale = 1; }
Hope that helped!
@@1upIndie i asked the question wrong, im trying to do a pac man clone and ive been trying to find a way to check for the closest next point on the path
They wont do diagonal movement, my logic is if the next point in the path is postive X, they will still look at that direction until it changes to another closest point
problem is i have only 3 brain cells and cant figure a way to do that
Thank you for this i video! It's really helpfully :) .
i want to ask you a question: if we have more than fifty "enemy" how can we improve the code? Simply by changing path alarm time to 1 or 2 seconds?
Well, you can marginally improve the code, so things like things like update lowering or doing a lot of code from one source (instead of all of them) can help this. But if you really want large numbers of enemies on the screen, then this system is not what you are looking for. It is meant for lower counts (50-100) enemies where they can go complext paths.
Hello, ty for this good tutorial!
I'm looking for how to use it with bigger monster but same wall size. (Exemple: enemy size 64x64 but wall 32x32)
If you have any advice for the collision to avoid that a part of the enemy cross the wall.
Acually yes, you simply assign a different collision mask (below where you assing the sprite) that is small enough instead of the default one that is being used when you assing a sprite to the instance of the enemy.
@@1upIndie Maybe I didn't understand something. But it doesn't seem to work :/
@@abesses6630 Hm, if you need some help, maybe go into my discord under the "help" section, there are always some guys that do help out new developers.
How did you set enemy animation? How did you know when enemy is moving up,down,left,right? I cant figure it out, can you help me?
This method changed the direction where you are goind and I set therefor the sprite according to the newly set direction. But that would look somestimes a bit twichy, so I update that sprite swap with an alarm event that updates around each 30 steps (half a second). Was that what you were looking for?
@@1upIndie How do you check in what direction enemy is going?
@@Artue0You know what, that could be a neat small video because I have seen that question being asked a few times. That will be done a few hours.
@@1upIndie Great! Thank you.
@@1upIndie Coudl you also include in this video how to check if enemy is seeing player please? Im making a game where enemies are shooting, and i want them to not shoot if they dont see player.
Very helpful Video! Thanks
Thanks, always glad I can be of service.
I love your content, you are much apprecitated!
Thanks, hope that stuff helps.
Thank you very much!
im having trouble trying to figure out how do i make it follow you through the rooms, do you have any tips?
Not sure what you mean by room. If you swap through rooms (aka, another level) you simply repeat the process like shown here. Or do you want to have enemies go from one room to the other with the player?
Liked, subscribed. Question. In my game if enemy has less than 10% hp, it is supposed to run away from the player, and i want to make it so that it runs using pathfinding, but I dont know how to do it. If you can pls give me some advice.
I tried to make enemy follow the furthest (from the player) point of the map, but sometimes the path to this point just does not exist.
Hm, what you can do is to go radially around the player (or rather a cone).
1st You would need to get the direction from the player to the enemy (aways from him).
2nd I would make a random difference from that direction (this is then a cone of possible directions where to go). I would say around +- 25 degrees
3rd so use lengh_dir from the player to get the specific new direction
4th check if if that spot is free (no wall there), if all good apply this new positon for the enemy to flee, if not start again with the 2nd step.
Hope that helps!
This is a longshot, but is there a function in gamemaker that lets you use the path system with tilemaps instead of a collision object? I just switched to using tilemap collisions with my player but quickly realised that mp_grid_add_instances doesn't support tilemap id's, I'm hoping there might be a fix out there that supports this kind of system?
Hm, interesting. I would need to check if that is possible since they (as you stated correctly) added tilemaps aswell to the mix or they will add that in the future.
this is aweosme
Yes it is sir!
@@1upIndie working on a roguelike so was doing som research on enemy tracking that's a bit complex.this will.be so useful to expand on
Thank you for the amazing tutorial as always!
So, this is a specific question but, I am making a game that has randomly generated maps, including obsticals. Will it matter where I put the NPC's? The whole gimmick of my game is randomization
Sure, if you do randomization you need to have a spawn controller where you spawn enemies. After the random maps are finished and check if on that random spot you can place an enemy with a collision check. If no collision is there this spot is free and you can save this in an array or instantly spawn an enemy there. Was that helpful?
@@1upIndie I understand yeah! So I'd just have to make the enemy AI check the map after it generates, right? I was thinking I could also create a clear area where the enemies spawn with no obsticals, then have them calculate from there
@@1upIndie just to insure I do it right, would you mind writing the first bits of the code? I'm not familiar with arrays, other than that they are essentially a list of information
@@hothead1546 That is possible also, to have "free" spots where all your generated maps don't place obsticles/walls etc. .
The video here does have one start assigment part where your obsticles are being marked as unpassable so that the enemies can create paths around them. So it makes sense to have an order or creation:
1. generate map with walls/obsticles
2. do the grid setup like in the video once
3. create enemies where they can be placed
@@hothead1546 I assume you are new to programming (which is totally fine, you get quickly lost in the vast amount of tutorials etc.), so familiarise yourself with the boring basics, because you try to do out of the box advanced coding which will very likly frustrate you.
I write that because this cannot be simply achieved with a few lines of code. Come in my discord and let's see what we can do here.
This video was very helpful to me, but I have one question: how to avoid stacking enemies in each other?
Well, that is much more complicated. You would need to ditch this "ready to use" system shown in the video and create your own pathfinding A* algo plus an anti clustering vector collission system.
@@1upIndie and do you know of any videos on this subject? I don't know how to do what you suggest. Thx
@@zarc677 I have not found any to be honest. All the vampire survivor games use build in collision systems (Godot, Unity, Unreal) which take care of that. GameMaker has none and so you have to build your own. I haven't found a solution that doesn't tank performance.
@@1upIndie Okay I see, thank you for your prompt reply.
thx!
let's say for example I had obj_player run an instance_destroy command when it touches the zombies. When I do this, the game crashes for me. I even made sure to put in a "if instance_exists" statement and it still crashes. I think it's because they're seeking the player's position rather than the exact coordinates. I'm not too sure, though. Any help would be appreciated. Very helpful video, though. You have my thanks!
You are correct in your assement here, the code looped in the alarm is getting the x,y value of the player instance, if it is not there (gamemaker cannot get values out of no existent references/data) the game crashes. Technically it makes no difference if you give some fixed x,y coordinates to search for or current player one's (it should not crash) and check if it exists. What you could is to create a player_Parent object and have 2 children (check out inheritance if you are not sure about it). The obj_player itself and a obj_dummy. The dummy is being spawned when you destroy the player on the same spot (when you destroy it). So you have in the search code then target_x = obj_Player_parent.x; target_y = obj_Player_parent.y; instead of the "old" code. You always have then a target coordinate That should fix the issue. Hope that helps!
Video on inheritance/parent child objects:
ruclips.net/video/ytoWx081WWk/видео.html
@@1upIndie Thank you sir. That's helps a lot with the player issue. You have my subscription. However, I have allies in the game that shoot at obj_enemy_parent and use the same path-finding scripts to get to them. This creates a similar, if not the same, issue, when they shoot the enemy and the enemy instance is destroyed. Even though there are other instances of obj_enemy_parent for them to seek out. It seems that the instance they're following get's destroyed before the path can update and seek another instance. I assume this is true, because the game randomly works fine and randomly crashes with a similar error message.
Edit: For some reason the game didn't like me using variables. Now instead of target_x = target.x and setting target.x to an instance_nearest command, I just set it as target_x = instance_nearest(x,y,obj).x. Idk why I couldn't have just used a simple variable. It crashes a lot less now for some reason.
And congrats to you for keeping up with a 2 year old video. Someone with as much dedication at that deserves more subs.
@@LuthersLounge Thanks for the trust in subbing. Hm, I wonder why the game is being unstable because normally it works or it instantly crashes (normal experience for the last 5 years with GameMaker).
Variables are pretty set in stone, either you declare them in the create even for further use or have temporary ones (var keyword) and can use them only in that event where thery are being declared. So it can be the engine (contact the offical YoYo help desk, it always has been not good on mac devices in the past) or code that does work wonky at times.
If you are unsure, maybe use the offical GameMaker or my personal discord channel and ask for help there. You can better answers there then me doing guess work (which sometime does help though).
idk where but ive also purchased this tileset/asset pack before with the zombies, character icons, buildings, cards, roads, etc. if you remember/know what its called please let me know cause i would buy it again in a heartbeat
That asset packs are from Malibu Darby, malibudarby.itch.io/
How can I make my Enemy go around the solids in a certain radius? my Enemy always clips through the wall and i dont know how else to prevent it.
Sorry, but I have no idea how to help you here. To have an allround system you would need to swap between the pathfinding and an additional instance control system of your own.
@@1upIndie Thank you
Thankx professor.
Hone your skills my pupil and you will also become one with bug report, haiiiisa.
@@1upIndie Yeah, I'm makinga a bug with a little game in it. ha ha ha ha
pathing works but my enemy goes halfway through the walls, somethings weird with the collision mask
Hm, did you try drawing you collision masks and see if that is the root of your issues?
In your draw event: draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom,1);
Was that helpful?
@@1upIndie i did draw the collision masks for both my enemy and collision blocks, both are working as intended but my enemy's collision mask is clearly going into into the block
nice video but get this I found out on certain dimensions the boxes are not equal l.(in different sizes))
grid = mp_grid_create(0,0,room_width/32,room_height/32,32,32)
and so like some dimensions work so what's the issue
Not sure what you mean to be honest.
When you add the instances with the function "mp_grid_add_instances(id, obj, prec)" you must set the third parameter as true.
@@aaronmaldonado6562 oh thanks man..😁 let me try that
what if i want the objectto go around multiple objects? I have my normal solids but i also have a moving solid, and i dont want the enemy to go through that either. what do i have to do to prevent that from happening?
also: im trying to use a random spawning system with the solids and now it doesnt work anymore. why?
Well, that is a bit more tricky since you "map" with the setup once where solids are and the inbuild A* search algorythm does create possible routes for each enemy via paths. But now you want to go from a once setup static setup to a dynamically updated one. So, you can do the setup phase each step which will take a toll on performance or you can create your own custom collision/route system which is possible but not an easy solution.
@@1upIndie Thanks
My only problem with this code is that all the NPCs are rubbing against the walls when trying to follow me. it looks very weird. any ideas on how to fix this?
Not with this system to be honest. You would need to create your own anit cluster algo with your own custom pathfinding algo.
I just tried your code, but it's not working, the whole path part. It's not drawing a path and the instances aren't moving at all (but the mp_grid seems to be working just fine), I wonder if these funcitons got broken by some GM update?
Hm, GameMaker updates have a tendency do break things, so it is not out of the possible realm.
Sometimes flushing the cache (clean symbol next to start icon) may solve your issue. If not, try the offical yoyo or my discord server and ask for help there. I cannot really help you in such a situation.
@@1upIndie okay I found help on the forum, looks like that if I make the enemies child of the collision object they just get stuck
One question how can i use this when i have no room size defined?
Like my room is 1 by 1 pixel big but due to a custom camera i can go anywhere i dont thik its a good idear to make a grid that is 100s of thousands of sqares big.
Technically you can have a grid of one pixel, but will become memory intensive. So it maybe would be better to have "bigger" squares so that the algorythm is less taxing and set the grid only on the area where you want it it be (video goes for the full room).
@@1upIndie its as of now a room without boorders so you can move as far as coordinats go to the 32bit integer limit
could it be possible to always update the grid possition so that it is always at your screen possition
@@boxedgamedev9462 You could update it, but the more you do that the more it will tax your performance. Just play around with values and condition until you find a good solution to your current project.
To it to work I need to watch Pathfinding #1 & Pathfinding #2?
Not necessary but it gives a programmer that is new in GameMaker context what is possible. The method in this 3rd video of this series is the most "complex" one and maybe not what is needed for your game.
What if you want the walls to be the only path, like in a citybuilder?
Hm, then this is maybe not what you are looking for. This is system is for dynamically guiding instances (heavier on cpu) around tricky obsticles. For a linear/fixed apporach/ways/road I would use the path system.
@@1upIndie Just wondering
im making a topdown game and the enemies dont go completely round the walls and go through it on many occasions any way to fix this
Have you tried my discord the "help" section? I cannot really do anything for you with these sparse informations.
I have a problem. My nemies get stuck on blocks moving to the player and I don't know why. please help!
Hm, not sure I can help you out without seeing your project (I cannot, I get too many requests for help). Did you try my discord help section? Maybe somebody has the same issue or knows how to fix your problem.
Does this work with mp_grid_add_cell? My enemies get stuck in the walls:/
(from a tileset)
Hm, if you do that during runtime, you would need to update the path of all entities walking around since you add a (mutliple) new cell(s).
I don't get it you create the purple enemy grid but it moves the ennemy don't understand why , when I try to do it, it lag so much it doesn't work and nothing happen.
When I reduce the size of the room it lags less but evrything disepear
I am not sure how to help you out here mate. In my discord you can try the help section, since you ask about basics.
Tengo un problema , y es que la room , las paredes , etc , estan de color verde y rojo , como hago para quitar eso?
No estoy seguro de cuál es tu problema. Pones todas las cosas en la habitación. Si desea hacer que las paredes u otras cosas sean invisibles, puede hacer clic en el objeto "visible" o en el evento "crear" visible = false; escribir
¿Fue útil?
@@1upIndie si , muchas gracias :]
Can't get it to work. Everytime a path is created the game crashes and gets a checksum error. Wondering it might conflict w the rollback multiplayer features. hm
Checksum for frame 120 does not match saved (-2144494780 != 823548680)
I am not sure how I can help you here plus I haven't done anything network related (checksum is a not readable/not closed network data) with GameMaker.
@@1upIndie Thanks anyways ^^, I'll have to make do w method #2 and design maps carefully around that.
I have a question when I run the game my enemies start moving but once the path gets updated they stop in one place and don't move at all do you have any idea how to fix it?
Dunno, check the "speed" variable ( i would draw_text it above the enemy). I guess your issue is that they are not running in a new path (so you are maybe not updating or something is missing to "kickstart" the new movement).
@@1upIndie Yeah speed was the problem I don't know why but in the path_start event when I was typing the built speed variable as speed it wasn't working but when I typed the exact value it worked, so thanks a lot
@@porucznikananas2600 Sweet!
how do i make the enemy collide with other enemies?
That doesn't work with this system (it is boxed and not meant for this), you need a your own custom A* search algo with anti cluster algo, which is not beginner friendly.
How do I make it so that the sprites don't phase through walls while using the path?
Well, you have the bounding box the instance to be bigger or same size as the Sprite or you draw the walls over the image (walls layer is on top of your sprites layer.
@@1upIndie I found the action that changes the origin of the object
Hey, so i followed this tutorial but i don't really know why, my enemies dosen't appear, i am the only one? did i do something wrong?
Hm, not sure how I can help you mate.
@@1upIndie No problem, thanks for your answer !
Did you do draw_self(); in the draw event of your enemy?
@@Infernoplex Yes, that but you see my enemies are those red/pink rectangles (sprite index). Here I simple do a "fake" draw event above the draw self, so that you can the see the box/rectangle which does the collisions/pathfinding and then the good looking sprite above it.
And when he can't get to the player, instead of standing still, how do I tell him to do something else?
Well, you then do this with a state machine. One is state = "following" other to be ide or even roam randomly.
@@1upIndie From my honest opinion watching your videos I do not understand how you do not have more subscribers, thank you for answering me 👍
Can you do it so they don’t follow the exact same path? Like they don’t essentially line up and group up together when moving to you
That will be fixed in the Hotline Series video.
@@1upIndie Hi mate - just watched the HL Miami vids on pathfinding AI, I didn't spot your solution to it in there. Did I miss it?
@@0ADNewbieRush Hm, it starts in Video "Hotline Miami Remake in GameMaker Studio #26" and is implemented there.
@@1upIndie Hi, I've gone through the vids again from 26 to 30. All of your examples involve a single player and enemy, so the lining up/grouping behaviour is never actually seen, and subsequently I don't see anything in the code that would negate it. You certainly don't draw any attention to it. It's got more mechanics, like the line of sight, etc, but I'm not seeing anything that specifically would prevent multiple enemies converging. I do have a solution that I'm trying to impliment in my own game, but I was really interested to see what yours would be, mostly to see if it was a more elegant sotution.
@@0ADNewbieRush I didn't implement any grouping/clustering code because the series was ended. There were a few more systems I originally wanted (patrolling, grouping, calling for reinforcements, stunlocks from the player etc.) to do but since view counts and watch time were abysmal I had to cancel in the end.
26-30 Were "only" doing a state machine that goes, follows and shoots. All necessary basic moves. I don't intend to futher the series or add more mechanics, so in that regard that is pretty much the end.
There is a good video on that, maybe that helps you out: ruclips.net/video/OmnUZM4-B6o/видео.html
If you make it so the enemies trail the pathfinder object loosley, you can get some very cool effects where it isn't as clustered. anyone have any good tips for getting them to avoid one another?
You can flag the enemies as walls also and give them a round bounding box. That is not the best way but works for small groups of enemies.
@@1upIndie I ran some updates as well to make it so that every update, it updates the navigation mesh to include pathfinder, so they have more boyd like behavior
@@fredxvi how did you make the objects loosely follow the path? Could you also share the code you used to make the enemies less uniform?
@@wyattputman1461 sure thing
@@fredxvi thanks!
Just a note, when 1up indie says it takes alot of perfomance, hes not joking. With my game the rooms are huge, 50,000 by 50,000 and i get a game crash error where gamemaker runs out of memory, when trying to draw the grid!
Holy! :DD
Can you give me the source code by anychance? Thank you!
Sure why not. Drop in my discord and I send you the project file.
Hi. I have an error, really weird one. U see, im using grid = mp_grid_create(0,0,room_height/64,room_width/64,64,64); (because i operate on 64x64 sprites) but this makes my grid draw... only half on the screen, left to be specific. But when i change room_height and width to room_height/32,room_width/32, grid draws normally (but works not as i intended) what the hell actually?
ibb co/KF7Q3kX (this is how it looks like when i changed room size to x2
ibb co/0tVwZ41 this is oryginal room size
put a dot between ibb and co cuz youtube deletes links ._.
Hm, that bug is super weird to be honest. No idea how to help you out mate.