Creating SMART enemies from scratch! | Devlog
Ойындар
Play the free demo on Steam!
store.steampowered.com/app/25...
Join my Discord!
/ discord
Veih is an amazing artist, check out their kofi!
ko-fi.com/veihart
I teach game development/programming courses on Udemy, check them out if you're interested!
Lua and Love2D:
www.udemy.com/course/lua-love...
C# and MonoGame:
www.udemy.com/course/monogame...
Music: Lake Theme from Pokemon DPP
Пікірлер: 370
I'll admit it - I didn't know what a raycast was when I made this video.
@Skimblie
4 ай бұрын
Just watched this video and I'll admit - I was waiting to hear why you weren't doing that :P
@SleepyBear_SB
4 ай бұрын
still very informative!
@ggrandfatherr2294
4 ай бұрын
i was about to say you literally made your own raycast
@Selrisitai
4 ай бұрын
I don't know if raycasting would do the same thing, but I really liked how your enemy really felt like he ran the corner looking for you, didn't see you, paused a moment in confusion, then gave up and wandered away.
@user-ex7ds3zu6d
4 ай бұрын
Lol I'm not great at this stuff but have used raycasts fairly often and I was curious if there was a reason you opted not to😂😂
One cool option is also breadcrumbs! You spawn small invisible objects behind the player that disappear over time and you make the enemies go in that direction...
@NotDaishoo
6 ай бұрын
just like in assassin's creed games....
@robertonome2448
6 ай бұрын
Hacky solution most of the time. Especially when u wanna add in different movement patterns. At most it should be used in combination w actual context steering behaviors (and pathfinding), not as the enemies' main form of navigation
@pulsarhappy7514
5 ай бұрын
Yes, a "last seen position" given to every enemy is a clever solution. When the enemy loses sight of the player, it should go towards a "last seen position" that it has, saved in its own script. When the enemy reaches this "last seen position", it has two possibilities: 1. Either from this new position it is able to see the player and will continue chasing them. Or 2. After getting to this new position, the player is still out of sight (they escaped), and the enemy returns to idle. It doesn't require a lot of memory, only a positon vector that needs to be assigned to an enemy when the player gets out of sight, and that is cleared if the enemy has line of sight on the player. At least that would be my solution to this problem.
@konradpiotrowski9549
5 ай бұрын
@@pulsarhappy7514 Yeah, this is exactly the same thing I thought about. Breadcrumbs solution feels like enemies could still find the player although he already managed to get behind two obstacles what could by kind of annoying. It would feel you are fighting dogs which sniff their way to you. Also, these breadcrumbs should be visible only to enemies which had LOS when player was running away.
@benjaminlehmann
4 ай бұрын
Nice idea. You could get some cool emergent behaviour too if you extended this to enemies. They could drop 'Alarm' bread crumbs, and then any other enemies that pass these will be drawn into the pursuit too.
very deceptively simple and performant way that's actually pretty realistic is for the enemy to move not towards the player, but towards the last spot they saw the player at. It's also cool because it introduces stealth elements where you CAN lose the enemy if you find a place to hide once line of sight is broken, but if they're following you closely they'll probably be able to see you after they reach the point. If you want to make it even better, you can make them go into a "search" state where they wander around randomly for a bit if they reach the point but still can't see you. If you want to get more complicated but make them even smarter, weight the random directions away from the direction they were just moving so they search an where you probably are and don't backtrack. Then put a timer on the search state so they go back to idle if they can't find you after a few seconds. That's how enemies in stealth games usually behave anyway.
@andrewluhmann3841
7 ай бұрын
This sounds perfect. I’m saving this comment!
@Challacade
7 ай бұрын
This is definitely a great option, and if performance ever becomes an issue with my implementation, I’d likely move to something like this. But check out the clip at the 3 minute mark in the video - I think this is where my version shines, because Last Seen At wouldn’t work fully there
@NateVolker
7 ай бұрын
storing a “last known player direction” vector the enemy could follow for some small amount of time if they still do not have line-of-sight after they reach the last known player location could potentially approximate more complex pathing
@j_razavi
7 ай бұрын
@@NateVolker I think this depends on the map design. If there are lots of nooks and crannies to hide in, then @Challacade' s method might produce psychic-seeming AIs in some situations. In that case your idea to store last known direction with last known location could work well (or other heuristics, such as moving towards the tile which can see the most if player not sighted from last known location, etc). It seems that @Challacade' s probably takes into account their intended maps too.
@DanielLCarrier
7 ай бұрын
@@NateVolker I think that's good because it makes it easier for the player to understand their thought process. They can see the enemy go in a straight line until they get sight of the player again, making it clear that evading sight is a reasonable option and they're not just using A* to track the player no matter what.
I was just watching a talk by Rami Ismail and he mentioned how you should fake smart AI instead of making actual smart AI. Although your set up so far seems more about pathfinding rather than making "smart" enemies, so you haven't dug deep into AI behavior yet. But it's something to consider. There was also a study done for one of the Halo games where players felt enemies with the same AI but dealt more damage were "smarter" even though the behavior was identical
@woody442
7 ай бұрын
I agree that hard coded behavior is easier to setup and easier to control, but I don't agree that it's the better solution in all cases and I believe with the ongoing advancement in AI it's only a matter of time for 'intelligent' enemies to replace hard coded behavior.
@_gamma.
7 ай бұрын
What talk is this?
@joestromo2592
7 ай бұрын
@@_gamma. Konsoll 2021: Rami Ismail - 10 Empty Slides. The AI stuff is just one small section but the entire talk is very good
@_gamma.
7 ай бұрын
@@joestromo2592 Thank you, it was an excellent talk!
@jokerCraz3d
6 ай бұрын
It wasn't that they dealt more damage, it was that they had more health. As a result they stayed alive longer for people to actually notice the behaviors the enemy AI had.
I'm so glad to finally be at a point where I can watch a short video like this and know exactly what I need to do to implement it into my game. This definitely beats having to watch 2 hr tutorials that have to explain each and every step.
@imcartermatic
Ай бұрын
How long did it take you to get to this point?
@Tocsiman
Ай бұрын
how can i implement it to my game? i dont know the name of these things, the dots that you make when you move and stuff can you please help me find a good video about it
Great insight! Enemy AI is a surprisingly nuanced topic and it's great you got it to work well!
Something which might improve the performance is to calculate the line of sight by checking if the line intersects with any of the collision geometry inside the rectangle formed by the end-points of the line of sight. This way you don’t have to do a bunch of collision checkes iteratively over the line’s length, but instead check only once per line. Not sure how your collision is set up, but this might benefit the performance, especially if you have to recalculate line of sight for every tile for enemy pathfinding too
@Challacade
7 ай бұрын
I completely agree; this would be a big performance improvement.
@chloroticleaf
7 ай бұрын
You would also want to only check LOS if the enemy or player moves and otherwise just reuse the existing calculation. This could also let you implement a lot of optimizations with pathfinding. For example, you could have the enemy "remember" where the player last was and take into account level geometry to make a guess if it should have LOS. Take an example where the player runs behind a wall, blocking LOS. You could then remember the position where they lost line of sight and try to move towards that, using a collider to move away from any walls, and assume that the enemy would not have LOS until it gets there. Then at the target point, recalculate line of sight. I'm positive there's a lot of issues with this though, as I thought about this for approximately 30 seconds.
@bobsmithy3103
5 ай бұрын
Nice idea!
That was a really fascinating video, I'm very interested in the way you tackled the enemy navigation/pathfinding to work in your game. It's a very good solution to the problem, and I especially like how you were able to use it to also create idle patrol movement too. Great game art as well btw, love your style!
Love the content! Always inspires me to work harder at game dev and making videos :)
I already really like the game!!!! Keep on the great work, man! Much respect .
Nice use of a bi-directional path finding ^_^, as you already have states for your enemies, it would be fun to see some "Elite" enemies order their minions around with "regroup" "swarm" "hold" "attack" actions etc. also would be fun to see if the slimes could coordinate a pincer attack or do a "wall tackle"
Pretty solid solution. I thought about maybe pursuing the last known location, but after thinking about it, I could see that having issues in itself.
Was going to say something similar to the breadcrumb idea, have the enemy store a sequence of last known player positions within it's detection radius, then have enemies pursue the latest position it still has LOS of. The breadcrumb is good because it only stores one copy of those positions though. One note about the breadcrumb idea is to only drop them if the player is within an enemy's detection radius to save performance. Another thing to consider maybe is having the enemy give up if it reaches the last position that was within it's detection radius and it still doesn't see the player. Then at that point it can choose a random direction to pursue based on the trajectory of the player's previous path. Say like within a 30 degree cone of the direction the enemy is already traveling. This way the enemy doesn't know where the player is, but it still goes in a pretty good guess of a direction.
Awesome devlog! This game is beautiful and looking great so far 😊
I really love the art direction of your game!
Really impressed here at the creativity in your solution to the problem. I wouldn't change it except for performance should that become an issue. Beauty of indie dev games is this type of uniqueness
I started following this channel a while ago because I love the devlog detail and style. Altho this game type isn't really my thing. You've won me over and I'm actually really hyped for this game. And cant wait to play it
These videos are so helpful for when I’m trying to problem solve. Legend 🤙
This is so cool, I love it. Will keep this in mind if I ever become skilled enough to implement something like this. Can't wait for this to come out
Love the visualizations. Keep it up!
The “last known position” works fine, maybe a lot easier too. You save the position where the LOS was lost and your mob will walk there. In the meantime, if the LOS became valid again, the mob ignores the last known position. This ensures that in corners the mob will “see” the player and acquire it as a target.
fantastic solution! I'm taking notes to use some of this on future projects :)
where is the code bro
A momentum-based pursuit approach (both linear and angular) would be interesting to try to make work. It has a little more persistence than stop-at-last-location, but it also allows you an opportunity to cleverly hide. Or, base some enemies on logic of “scent” instead of “sight”. Could be a fun mix.
Something that could really add to the enemy system is different enemies pursuing the player in different ways. Maybe something small and dumb like the slime will just go at the player, but maybe those projectile launching guys from the cloud area back away from the player, and can even fly off the stage. a ranged enemy wouldnt want to go towards the player, it would want to be at a range. I think it could add some depth where different enemies instead circle, flank, or kinda bait the player instead of just going straight at them.
i love the pokemon mystery dungeon music at the start. also nice video, the games come a long way.
I always get so hyped whenever you upload
Be careful comparing lists against lists. It can get very performance heavy. Usually A* only checks one cell at the enemy position at a time. Then uses neighbour checks. You get neighbours by carrying the grid with you. It's a whole thing but imo well worth the performance increase.
Great Video! Very informative. Thank You! :)
You just earned a subscriber friend
Even the worst of the days become good days whenever I see that Challacade uploaded another video!
That's a very cool system! Since I make most of my games in Rust, I actually coded my own A* Pathfinding library and usually use that haha
I liked that it is more like a "pseudo"" code rather than actually showing the coding itself making it usable throughout different engines.
Really dug this implimentation. Probably pretty similar to how I would have approached it myself!
3:19 my suggestion is to set a vector2 to the players pos every frame as long as they’re in LOS. Then if the play goes out of LOS the enemy goes to that vector2 where the player last was in LOS. This is just how I would do it and I hope I explained it well! I love your devlogs and look forward to them every time!
Maybe this has been mentioned already, but I would definitely check out DDA algorithm. I just added a modified version of it to my game for raycasting movement making sure things stay within tiles flagged as walls. Modified in a way to not check every single unit step on that line from it's origin point, ei your enemy. If you run into performance issues you could use this method provided you assume collisions are set to some tile, then handle other special cases some other way.
have you looked into context based steering? its a system im using in my game that can create very complex behaviors for ai when you combine it with state machines. in a nutshell the enemy casts rays around them, each ray has its own "interest" which is calculated based on the dot product of the rays angle to the target point you gave the ai. interest also gets set to 0 when the ray collides with an obstacle (or anything you want the ai to avoid), and then the chosen direction for the ai to move is calculated by multiplying each rays angle with its interest and then adding all those values together. this system is great as it automatically allows ai agents to make microadjustments to their chosen direction based on whats happening around them. when you have large groups of enemies they will automatically avoid clumping up and the way they move around and avoid eachother and obstacles looks very lifelike. you can also create behaviors like strafing around the player in a circle very easily with a little math. you should really look up context based steering
I would've just made the player periodically drop breadcrumbs, and if the enemy loses sight, it goes to the most recent breadcrumb. Then if he doesn't find you from there, you lost him. Seems a lot simpler to me, and also has some personality.
Increasing enemy AI is another way of having a harder difficulty without it feeling artificial. Just increasing attack power from enemy attacks can only do so much.
It looks like smart movement! I might not be the only one who liked the aesthetic of the colored dots, did a great job explaining!
@Challacade
7 ай бұрын
I spent at least 30 minutes deciding what colors to use, I also like how it looked!
Tried the demo, really nice I like a lot the style, it remembers me of Minish cap. Found a couple of things you may already know, anyway in the clouds map on those platforms that start moving when you are in their center, if you drop a weapon when the platform reaches the new position it just falls down and you lose it. In the first forest instead, I swam to the east and found an invisible wall in the river. You may just place some rocks there, right now it feels strange. Lastly a slime followed me inside the water making a strange effect. Hope this may help you. Good job anyway I hope the final release will be even more fun!
I'd consider make a line of sight cone effect, and have the monster patrol in a area around where the player was last scene. This then can treat it in a aware, caution and danger state. Then put indicators such as a 1-10 and based on proxminity, movement within a certian range and other noise raise alert state. You can also give different monsters natural behaviors and routes, that would make sense for yheir organic function. Tbis is in some games monsters will feed on other monsters, to for instance incresse their health if low. Theyll seek out and devour weaker monsters to restore their health before attacking. Or try to put obstacles or traps for the player, to slow the plsyer down so they can find weaker prey or a means to heal
great explanaation buddy, i ll go check your udemy too
Bro, take care of your game's performance, to LOS, use a raycast, and to let the enemy chase the player even when he loses the LOS, make the enemy go to the last position when player was sighted, or use a AStar algorithm to pathfinding the closest path beetwen player and enemy
@notadev9000
7 ай бұрын
You just described what he's already doing. And using AStar would be more expensive because of the pathfinding.
@gustavols6699
7 ай бұрын
@@notadev9000 I hope so, but since he didn't go into much detail about his implementation, I think it would be useful to say so
@robertonome2448
6 ай бұрын
@@notadev9000sounds a lot more expensive than Astar, as its especifically optimized for that task, which doesnt seem to be the case of his algo... let alone for the cases he actually wants to do anythint else than follow the player in a straight line (strafe around, zigzag, hit n run, flee, etc)
@maervo4179
2 ай бұрын
@@robertonome2448 Actually it depends how much enemies he wants to have, neither of these solutions would be great with a lot of enemies. Calculating A* with hundreds of enemies and you have a game with 10 FPS , especially if you have many obstacles. I think the best would be to create some flow field
@robertonome2448
2 ай бұрын
@@maervo4179 this clearly isnt a horde game...
An idea is that whenever the player leaves an enemies line of sight, the enemy will walk towards the players last location. Once it reaches the last location, if it finds the player again, it can continue chasing, but if the player isn't near their last location then go back to idle state.
Very cool! One possible solution: You could make the enemy go to the last known position of the player's position (Store the player last position before it goes out of sight)
@Challacade
7 ай бұрын
This option is simpler and less resource-intensive, but it couldn’t handle pathing like mine does at the 3min mark in the video
@freddyspageticode
7 ай бұрын
I think the simpler solution is fine though, especially for simpler enemies as it makes them easier to get off your tail. For more difficult enemies the more complex solution might feel more warranted.
Make the NPC chase a point that represents the player's last known location. Update that location every time the line of sight check to the player succeeds. If the enemy reaches the last known location and the line of sight check to the player fails, then the NPC gives up and goes back to idle. This way when the player runs around a corner, the enemy will go to that corner to look for the player. For the player to escape, they'd need to quickly get out of line of sight of that corner before the enemy reaches it. A more complex but more effective addition to this would be for the player's movement direction to be added to the last known location object. When the enemy reaches the last known location, it could continue moving in the player's last known direction. This would force the player to have to quickly go around multiple corners to avoid the enemy finding them. This is more realistic and somewhat on par with human behaviour.
pretty smart and clear, thanks!
One interesting way to have a more "non-enemy relationship" type of AI is through a Utility System that decides what Behavior Tree to execute based on its modular list of Considerations. Although, this is far easier said than done. If it turns out uber sick, I kinda wanna make a video like yours. Your channel and devlog adventures are an inspiration!
Wouldn't it be simpler if the enemy just follows the last line of sight to the player before losing sight?
@RaonakDM
Ай бұрын
Yeah, Just store the last sighted coordinates on the enemy instance. it goes to if it loses line of sight. It doesn’t require every tile doing a calculation and can scale for if there’s multiple players. The dev’s solution feels a bit over engineered, but it probably has its advantages.
Love the update. You should consider having the enemies talk/interact with eachother when idle. Making them feel a little more alive. Maybe use different symbols like ! 😊 and ❤s.
A simpler way would be 1) the monster can try to keep going the direction it WAS going 2) the monster can kind of randomly move about in a dumb "search" until such time it DOES have los with the player so effectively the monster can go into a third mode, a 'searching' mode (like with a ? above its head maybe) where it first tries to keep going forwards for a few seconds and then randomly searches. My other thought and addendum to this is to have a monster keep track of nearby collisions to itself in all 8 cardinal directions, and so when randomly searching it would never try to go that way (into a wall) but instead pick other paths. I am trying to do a very similar thing but in 3D with no navmesh so wish me luck. Im going to attempt to use the above strategies in 3D - should be interesting
If the player is suddenly not in los, the enemy will move to the last location of player in los
keep up the good work
Man, this is awesome!
Instantly subbed after hearing the song
i had a simmilar thing except i made it so each enemy had some form of memory and remembered the last player position after loosing los
Woo! Looks great!!
Thanks for this informative video
What if you make the enemy remember the place the player was when the line of sight was last maintained? If it's broken, you make that point the new location to reach for the enemy. If there is still no line of sight with the player when it gets there, it returns to idle state. This also gives a realistic chance for the player to outrun the enemies.
If the enemy can see the player, store the player location in a "last seen at" variable, then regardless of line of sight, move toward the last seen location.
hi @Challacade , What game engine did you use to build this game?
Which programm do u use for create thw game?
Is it easy change multiple enemy code for something like that ? Like can you creat 1 script and assing all enemie to the script ? idk im new i try to understand
Looks pretty cool
you can cutdown on the amount of line of sight checks to save on number of computations you can probably have some sort of look up table where you can quickly check if there is line of sight between the tile the player stands on and any other tiles instead of preforming the check for every tile.
I didn't expect the tile grid active state method. I was expecting it to use a look behind, and simply move toward the players last known position, until it regains los. You method allows for potential good solutions, like the enemy taking a shortcut around a barrier, vs always the chasing line. *It could make for an interesting enemy to combine the 2 ideas, but inverted,* so it looks for the gap in data and chooses the _opposite_ side as where the player just left. Intentionally, this enemy would instead of opting for chasing around an object, prioritize cutting the player off at the other side. That would make for an easily exploitable enemy, but very different than standard enemies, and nasty in combo with regulars, as you run and gun gets cut off.
The double LOS solution is actually really darn clever :o
A solution for your issue a friend of mine did in college for his thesis was prebaking a few paths around the map whenever a level was loaded and used a raycast to check if the enemy was in line of sight with it's target, if the target was in los they'd gravitate to the closest node on the path and follow the path towards the closest node to the player till los was achieved. Had some minor issues but seemed quite performant. I'm paraphrasing obviously but it's interesting how you both came to similar solutions.
Anyway to possibly release the tile map code for the enemies or have a possible tutorial on it? I am creating a game and have been looking for good enemy tracking
Very creative approach! I usually go for A* pathfinding or using a navmesh. I wonder how well this performs.
Vampire survivor just says fuck it my enemies are ghosts
Very cool AI logic. I have wondered how to code a roaming mode for my enemies. This tile logic looks like it will work really well. Thanks for the great visuals on how it is broken down. Does any of your current courses explain how to setup this particular AI logic?
@Challacade
7 ай бұрын
The courses don’t get that technical, they’re more beginner focused. I’d love to make more content detailing stuff like this!
@taunhawk9888
7 ай бұрын
@@Challacade Please do! :)
So you effectively made your own pathfinding, pretty cool
I think you should add a cool-down to weapons, it forces the players to use a variety of weapons but it doesn’t completely get rid of any weapons and it can be used strategically in combat, I also think you should be able to equip a permanent ability to a weapon also adding to the strategic aspect of combat and allowing the player to in a way customise their favourite weapon
@OwenAFK
6 ай бұрын
The cool-down would work where each weapon has a certain amount of uses and when the player maxes out the weapons uses it takes a certain amount of time to recharge depending on the weapon, it’ll force the player to use a variety of weapons and form a unique play style depending on which weapons they use the most.
It was very interesting, this video was cool. I think it would be great if the enemies would look left and right after they lose a player.
This is some great tracking, quite impressed. Im curious could it be possible to do a check to see if the enemy has seen you in the last few seconds, and if it hasn’t it takes it as it lost its target? I think this would make it seem like the enemy is searching around for you but cant see you through walls still.
What if it is a target point around an obstacle that enemy wants to reach? This target point is not moving like a player meaning we cant use breadcrumbs behaviour and line of sight behavious. How would you solve this?
Do you use gamemaker studio 2 to create that game? looks pretty cool
Awesome logic!
a question (im not a programmer so im genuinely asking), wont it be easier to store the last position of the player which had line of sight with the enemy and make it move toward it?
@Challacade
7 ай бұрын
Your idea is a lot more efficient, and would work for a lot of scenarios, but when you need some more complex pathing, like at the 3min mark in the video, I don’t think last known location alone would be able to do that
Nice vid. Are you using behavior trees or state machines for the enemy ai?
I'm new to all of this and getting a hang of things, but wouldn't it be able to give entities some sort of "memory", just let them remember where they saw the player last and let them move there?
Another good way to make enemies look for player when they lose sight of him, is going to the last position the player was at before they lost sight of him and then checking if the player is still visible, because the system you have rn is very good but might cause an issue that makes chasing never end, just a suggestion feel free to take it or leave it, I also started developing my own game not long ago so it's always fun to see how other people do things😁
Congratulation, you invented navigation and sight perception!
Now i have no game development experience (and i know this is a old video) but couldn't you make it move towards the spot where it loses LOS?
I normally use floodfill from the destination position in a 2d grid. As soon as I reach the starting position via floodfill, I backtrack through the values to get the shortest path to the destination.
This would make for a great stealth mission or something
I don't know if you hand draw your levels or generate them, but you can generate path nodes either way and just have the enemies follow the nearest path that they last saw you along until they get tired of chasing you, as in via a time limit to their agitation. Basically, LoS would be the key metric, but once that's lost they could follow path nodes closest to where they last saw you and scan their radius while the timer counts down, unless LoS is picked back up, and then the timer restarts. If you don't know how to generate path nodes, there's several videos showing various techniques for it, and there might still be one that explains Unreal's automatic path node generator.
Alternative AI player tracking thats maybe easier or simpler- if enemies lose LOS while chasing then store the last known coord of player pos and set that as the next target location for the AI, if it gets there and player is still not in LOS then either cancel chase or start some kind of "search" motion pattern where it does a circle or figure 8 or triangle that lasts for X seconds before returning to idle or patrol behavior.
I think I would give the enemy a searching state. when it first enters this state, it continues towards where it last saw you, then goes a short direction in your last known velocity. if it hasn't found you by this point, it wanders for a bit then reenters idle state. having your own los data on the player seems useful though.
Which software do you use to create sprites?
As a very beginner this may be question bit off... but I wonder how much is this resource intensive? Since you check every frame for that LOS and have lots of points which may be on / off very quickly.
Very cool!
When the enemy can no longer pursue the player because maybe they ran away and the LOS stuff blah blah, maybe you can put a question mark on their head to make them look confused before they return to their idle position
amazing!!
I do LOS with a raycast from the enemy to the player. Add a layer mask for obstacles and if hit.collider!=null it means there is an obstacle in between, so LOS=false, else, LOS=true.
hello, i am trying to creat my own indi rogulike and your vidéos helped me a lot, but i have a question, are you using unity or an other game developement engine ? sorry for my english, i am french
Hi, can u tell me what engine, language, tools you are using is this demo? It feels so good.
I guess i would just add some variable to the enemy that keeps track where it has last seen the player. If it reaches that point, it just raycast to the player and checks if it has a new line of sight. Just like anybody else would do - no magical "i know i have line of sight from that point" stuff. And it should be much more performant than throwing a whole lot of raycasts from a whole lot of positions.