Here's the basic Enemy AI I've used in several of my games, very easy to make and easily expandable to fit any game! 🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
@arturkaczan17764 жыл бұрын
I just have bought a Hyper Knights for fun :)
@willkeith86994 жыл бұрын
Does this work for 3D projects as well?
@CodeMonkeyUnity4 жыл бұрын
@@willkeith8699 Sure, everything is working with Vector3
@aceofdiamonds12854 жыл бұрын
Will this work with nav mesh agents attached?
@Dailymoresuccess4 жыл бұрын
Can you show tutorial for pathfindingMovement ?
@Adidaas4 жыл бұрын
Hahah, I can't believe it. I always thought that State Machines was gonna be something complicated to learn. But State Machine is literally just switch cases of different enums. That's super straight forward. Maybe it's just the name ."State Machine" sounded so intimidating. Thanks for the clear and concise tutorial! And especially thanks for not murmuring and for writing correct and clean code to follow!
@CodeMonkeyUnity4 жыл бұрын
Hehe yup the name State Machine does sound intimidating, I had that exact thought when I first heard the term until I realized that's what I had been doing all along.
@anjobihis20524 жыл бұрын
This is so true lol!
@ludovicmahieu82784 жыл бұрын
The version with abstract state is much more complicated (but powerful) :)
@ludicrouS_4063 жыл бұрын
State Machine are just facy words for a simple thing that makes people feel smart 😂
@asdfghjkl-jk6mu9 ай бұрын
@@ludicrouS_406 what else would you name it to describe it accurately lmao?
@minibubblegum51083 жыл бұрын
PLEASE BEAWARE for people confused at different codes from 5:53, there has been some slight tweaking in values, so practice with the project files given above. I depressed myself for using 1f as reached position distance. if you are deleting the Enemy AI script and creating your own in the project files, see the Enemy AI script in the files first. And thank you Code Monkey for showing me a new way to use A star.
@serialchiller91834 жыл бұрын
This intro song has become iconic. Please don't change it even though you change the visuals. X) Keep up the good work!
@alperatmaca64303 жыл бұрын
dude i've been searching non-stop for a tutorial ike this! thanks for the amazing tutorial!
@ScrubInstitute3 жыл бұрын
Why I like code monkey? Because he explain everything in a simple way. He deserves more subscribers. If you want to get more views, I recommend to change the thumbnail style.(just a suggestion)
@CodeMonkeyUnity3 жыл бұрын
I'm glad you found the videos helpful!
@ScrubInstitute3 жыл бұрын
@@CodeMonkeyUnity why don't you make a racing game?
@neozoid70092 жыл бұрын
Awesome Tutorial and enemy system
@fardin3m394 жыл бұрын
its so awesome he popup all previous tutorial that maybe you have question about at the start
@tyleranders99724 жыл бұрын
I agree
@elroymusic63634 жыл бұрын
One day you will have created an AAA game in the Code Monkey Cinematic universe when combining all these tutorials.
@commissargab61813 жыл бұрын
A triple a monke gem
@TheGozeraye Жыл бұрын
I'd be so lost without these thank you!
@jvcmarc4 жыл бұрын
hey, can you make a video about how to make updates/patches for a released game?
@gouravsoniya23669 ай бұрын
@Shoo897 she was little straight forward 😂
@abandonedgoals40674 жыл бұрын
Just wanted to say, love your channel! :)
@CodeMonkeyUnity4 жыл бұрын
Thanks!
@matt10y274 жыл бұрын
This is cool! Such a clean and concise way to implement the state changes with an enum and then a switch case.
@TheStigChristensen Жыл бұрын
Would love to see a similar video for a friendly AI! A bot to help in singleplayer, when there's not a second player around
@electromorphous4 жыл бұрын
You're absolutely owning it with these videos. These are really very helpful.
@medmel21604 жыл бұрын
thanks for the quality content as usual. Gratz in advance for the 100k sub ! You deserve it and deserve much more
@CodeMonkeyUnity4 жыл бұрын
Thanks!
@generichuman_2 жыл бұрын
Damn, I never thought of just having a static instance to use in another script. Avoids making spaghetti with dependencies, super clean!
@Andrew90046zero4 жыл бұрын
I haven't gotten deep into Ai in my game yet, and I was planning on making an entire fully blown State Machine class just to do wandering and movement. But this is exactly what I needed. And When I get around to it I will actually do what you did with the enums.
@USBEN.2 жыл бұрын
Beautiful.
@Nicoulex4 жыл бұрын
Your channel has insane content ! keep on rockin'
@rafaelcorrea79594 жыл бұрын
You should publish Code Monkey utilities as a free asset in the unity asset store.
@filipgawlik32594 жыл бұрын
And this time I was not disappointed.
@aggressivemastery4 жыл бұрын
ECS? DOTS? Love you
@adansmith61746 ай бұрын
The best tutorial!
@insaneduane3 жыл бұрын
Thank you for this easy to follow and well explained tutorial on making a State Machine/FSM. Many other videos on this subject tend to get convoluted and "lost in the weeds" so to speak. I've used the Mecanim system as a FSM but I've found that to be a bit buggy (OnStateEnter and OnStateExit seems to not always work (probably my fault)) so I used your method and my VR zombies are acting and sounding like I want them to. I liked this video and I am subscribed. Thanks again!
@CodeMonkeyUnity3 жыл бұрын
Thanks! Glad you liked it!
@anjobihis20524 жыл бұрын
Code Monkey, how did you learn to code like this? Is it because that you code so much and research by self-teaching yourself i.e. reading C# and unity API documents? Learning from others? How did you come up with this advanced yet simplified codes?
@CodeMonkeyUnity4 жыл бұрын
It's really all about experience, I've been writing code for 20 years so in all that time I've written some basic AI implementation dozens of times. It really is just trial and error, start trying to do something, think of exactly what I need to accomplish my goal, and try to make it while constantly trying different approaches, reading the manuals and googling for answers. So yeah, the more you do it the better you become. Best of luck in your own journey!
@anjobihis20524 жыл бұрын
@@CodeMonkeyUnity Thank you so much, Code Monkey! I appreciate this a lot! And your videos are sooo good!! Keep em coming! :D
@rahulkumarjha24044 жыл бұрын
Thanks for this awesome tutorials .
@II-wu3wz4 жыл бұрын
Where can I find "EnemyPathfindingMovement" you mentioned? You said you created it in another video, is it A*?
@CodeMonkeyUnity4 жыл бұрын
Yes it's A* kzbin.info/www/bejne/l524YWeeq99pgpY
@II-wu3wz4 жыл бұрын
@@CodeMonkeyUnity There is no EnemyPathfindingMovement, nor a GridPathfinding, I watched every Tutorial for this, it's a bit frustrating. :D I imported now parts of your project and adapted it to my project, but I can't access namespace GridPathfinding, in EnemyPathfinding it throws me a nullreferenceexception at line 97 "pathVectorList = GridPathfinding.instance.GetPathRouteWithShortcuts(GetPosition(), targetPosition).pathVectorList;" But I have the GridPathfinding in my Project, can you help me? I also did a Debug, the reference is just null, the folder for namespace GridPathfinding is in the same folder for me other AI stuff. And in which tutorial you created all this stuff? Definitly not in A* :D I have to add: Reading all the other answers you give here seems like you don't really know the content of your own videos, there is no EnemyPathfinding, no GridPathfinding.
@vishwahsiva87384 жыл бұрын
@@II-wu3wz seams like the codes are in EnemyAI.unity pakage check it out
@ceciruiz42623 жыл бұрын
@@II-wu3wz I have the same error and I haven't found a solution :(
@TheKodiakDJ3 жыл бұрын
I don't know if I'm in time to help anyone out in this thread, but for people looking for those scripts in the future, they are in the subfolder TopDownShooter\Scripts in the EnemyAI unity package.
@tostpl82584 жыл бұрын
I think it's really good thing to show us your function (like getrandomdirection) . Sorry for my English if I did smth wrong
@lennyseed92553 жыл бұрын
Thank you for this awesome video
@Stinger-rq4gy3 жыл бұрын
I saw this its great, thank you sooooooooooooooooooooooooooooooooooooooo much.
@ezekielakande55014 жыл бұрын
Finally found someone useful
@CodeMonkeyUnity4 жыл бұрын
I'm glad you like what you see!
@david-spliso19284 жыл бұрын
Thank you CoMo.
@juicedup144 жыл бұрын
Thanks patrons
@glebgrozin68724 жыл бұрын
You're the man. Bless
@levanapakidze16064 жыл бұрын
isn't returning a static instance of a player game dependant code ? what if I attach that script to multiple instances ?
@CodeMonkeyUnity4 жыл бұрын
Yes, if you have a design that involves the enemy targeting more than just the player you need to modify that.
@Exisss4 жыл бұрын
Really Helpful, as always :)
@carrihook1094 Жыл бұрын
When I download the project I get the error LWRP does not exist in the namespace UnityEngine.Experimental.Rendering and The type of namescape name 'Light2D' could not be found
@CodeMonkeyUnity Жыл бұрын
LWRP has been renamed into the Universal render pipeline, I covered that in the FAQ on the download page, you just need to change the using statement
@SwampySongs3 жыл бұрын
Do you recommend navmeshes for things like this? The problem I run into is adding complexity/randomness to a navmesh.
@CodeMonkeyUnity3 жыл бұрын
Your Movement method is separate from the AI logic, you can use a NavMesh or just an A* Grid or in the video it uses no pathfinding. All of them work just fine.
@SolidMotionVFX3 жыл бұрын
Great video. How do i setup so enemies if close to each other they should avoid on and other.
@pythora41734 жыл бұрын
I downloaded the project files and put them in Unity, but it didnt work because there were so many errors. Fix?
@CodeMonkeyUnity4 жыл бұрын
What didn't work?
@pythora41734 жыл бұрын
@@CodeMonkeyUnity I'm not really sure, but the enemy ai script had a lot of error messages
@estusmedia18874 жыл бұрын
I've followed this up until the point where you run the first test, I have all of your project files but when I try to run the test with what i have so far I get an issue with Object reference not set to an instance of an object EnemyPathfindingMovement.SetTargetPosition and because of it my Enemy won't move at all, how do I fix? The error only appears on play.
@CodeMonkeyUnity4 жыл бұрын
You have something set to null, add a Debug.Log to figure out what it is
@estusmedia18874 жыл бұрын
@@CodeMonkeyUnity I eventually figured out it's tied to the fact I don't have the Aim System because I'm looking to make a Melee character, but it seems in order to use the Pathfinding, you need to use the aim system, which then involves me basically needing to use the entire project for the topdown shooter due to how everything is linked together?
@CodeMonkeyUnity4 жыл бұрын
@@estusmedia1887 The Pathfinding does not require any aim system at all, it just has a Grid and calculates a path, it has no concept of Units or Aim or anything, it's a completely independent system. Check out the Grid System videos and the Pathfinding one kzbin.info/aero/PLzDRvYVwl53uhO8yhqxcyjDImRjO9W722
@estusmedia18874 жыл бұрын
I've done both of those just having difficulties with this one now, I'll come back to it when I have a better understanding and experience and hopefully I'll be able to understand, appreciate all the great videos!
@MarkFilliph2 жыл бұрын
very useful video! thanks for sharing! Which video is the EnemyPathfindingMovement script? I can't find on your channel.
@CodeMonkeyUnity2 жыл бұрын
I covered A* Pathfinding here kzbin.info/www/bejne/l524YWeeq99pgpY
@BlastGamer77 Жыл бұрын
@@CodeMonkeyUnity Problem: Absolutely nothing on the enemy pathfinding script is in that video.
@thederbly6009 Жыл бұрын
Is the path finding script required for this to work?
@dextermunashemuwodzeri9424 жыл бұрын
Can you please continue making more AI tuts
@TalkingRaven_2 жыл бұрын
Would creating state_class that inherit an interface Istate with a dosomething() function and then using them as a sort of currentstate.dosomething() for the update function be advisable? or is Switch case still better? I'm currently looking into it for scalability in terms of AI behavior so it can still look clean even with a lot of different states.
@CodeMonkeyUnity2 жыл бұрын
Yup that's a very valid approach and if you do have tons of states then yup I would recommend that over switch states.
@TalkingRaven_2 жыл бұрын
@@CodeMonkeyUnity Thank you for the quick reply!
@davestomper3428 Жыл бұрын
what do we do if we don't have your previous scripts already ?? I downloaded the your utilies are they in their ????????
@CodeMonkeyUnity Жыл бұрын
What scripts? the point of this video is to learn how a State machine works, every game is going to have different AI specific logic, there's no point in copying the specific logic I used in the demo
@raposaarvorelua40994 жыл бұрын
thank you for the tag "unity 3d" when its not for 3d
@CodeMonkeyUnity4 жыл бұрын
Everything shown here works exactly the same in 3D, all the functions even use Vector3's Go ahead and apply it to your own 3D meshes and everything will work.
@dementovoid22552 жыл бұрын
How can I get EnemyPathfindingMovement to be recognized by Unity? Do I have to follow the A* Pathfinding tutorial before I follow this tutorial?
@CodeMonkeyUnity2 жыл бұрын
Yes, or use any other pathfinding system you want
@akashverma42804 жыл бұрын
Hello, thanks for tutorial! I wanted to ask an unrelated question. Do you think making mobile games as an indie dev would pay off? I'm in last year of graduation of my CS degree. I'm thinking of trying to pursue gamedev full-time.
@CodeMonkeyUnity4 жыл бұрын
Definitely give it a try, especially while you're still in school, but don't risk going at it full-time, do it as a side project along with a stable job. It's an extremely competitive industry and very difficult to make a living kzbin.info/www/bejne/jJ3GoKNmqt15f7M
@akashverma42804 жыл бұрын
@@CodeMonkeyUnity Thanks for taking time to reply. I have already watched that video cuz I'm already subbed. It had some nice tips. But working with a full time job would definately wear me out. I have plenty of time now, I'm at home due to current pandemic situation, I got no loans to pay and I have no urgent need for money. What I'm saying is that, I try gamedev till my graduation and see how it goes. And if it didn't go well I'll say goodbye to it and get a corporate job, but if it did go well (ik chances are very thin) then I consider it doing full-time. Also, where I live, cost of living is less. I could really use some guidance right now. Because I don't know any game dev in person. Thanks for reading.
@ChadRepson Жыл бұрын
Thanks code monkey!
@MrFarkasOfficial4 жыл бұрын
alright, alright, you`ve got my subscription.
@CodeMonkeyUnity4 жыл бұрын
Glad you like what you see!
@MrFarkasOfficial4 жыл бұрын
@@CodeMonkeyUnity i`m still a noob though. having trouble with the EnemyPathfindingMovement part of the void awake function. console says the namespace can`t be found. my guess is i need another c sharp script, the EnemyPathfindingMovement script but i don`t know where to find it.
@MrFarkasOfficial4 жыл бұрын
@@CodeMonkeyUnity nevermind, solved! :D
@RawHunterX4 жыл бұрын
Very informative, if youd like to expand upon it in the future, heres a suggestion: Do the New Mario Bros. Goomba behaviour. Basically whats new compared to the old ones is that besides patroling and falling off edges, it siwtches to chase the Player if in sight. However, it also pauses for a second, jumps up a bit, then it charges faster and if you jump over it, it changes the position to face the Player but slides a bit backwards due to the charge momentum.
@CodeMonkeyUnity4 жыл бұрын
Yeah doing some Platformer/SideScroller AI is definitely something I want to cover.
@troelsholm97613 жыл бұрын
So if i don't use your utils, how do i do the code then? public class Patrol : MonoBehaviour { public static Vector3 GetRandomDir() { return new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)).normalized; } private Vector3 startingPosition; private void Start() { startingPosition = transform.position; } private Vector3 GetRoamingPosition() { startingPosition + GetRandomDir() * Random.Range(10f, 70f); } }
@josueccama3034 жыл бұрын
hi, nice video. Please make video about isometric tile map with ECS. thanks
@Irategamefan3 жыл бұрын
I'm just wondering but could this work in a 3D space? By Space I mean Space like a flying sim?
@CodeMonkeyUnity3 жыл бұрын
Sure, the logic is based on Vectors, it doesn't care if those vectors have a y of 0 or not
@rameezsafdar65634 жыл бұрын
This is so informative, i wish you had an advanced AI tutorial as well
@bellatorpoeta3 жыл бұрын
How would I apply this state machine to a turn-based system with several enemy units? I would need to keep track of which unit is being controlled as well as have an indicator to not go to a new unit until done, but doesn't break reset the variables?
@CodeMonkeyUnity3 жыл бұрын
Each Unit would have their own state machine and then a general Turn System would handle who is active, I covered something like that here kzbin.info/www/bejne/ZoK4YayMZaiMipY
@Hypocat4 жыл бұрын
Hey, I hope this is not stupid question but where is the video where you do the EnemyPathFindingMovement? I can't find it.
@CodeMonkeyUnity4 жыл бұрын
Here kzbin.info/www/bejne/l524YWeeq99pgpY
@Hypocat4 жыл бұрын
@@CodeMonkeyUnity thank you very much.
@terrytech88124 жыл бұрын
How would we go about making the enemy avoid walls ?..... and without the NavMesh System. Well is suppose they cant see you because there's a wall so make them forget about you and target something else randomly. So then it comes down to using a raycast and detecting if the enemy has line of sight to its target.
@Sartoris364 жыл бұрын
Thank you for this video! Do you have any suggestions on how to make the enemy avoid obstacles without using pathfinding? Perhaps by turning when encountering an obstacle, or something similar? That would be very helpful.
@CodeMonkeyUnity4 жыл бұрын
If you just want avoidance like keep away then just keep a reference to it and test the distance. But if you want avoidance in order to reach a target then thats the definition of Pathfinding so I'm not sure what you're exactly trying to do.
@Sartoris364 жыл бұрын
@@CodeMonkeyUnity Thank you for your reply. I should have been clearer: what I am referring to is a system for the enemy to chase the player or look for him without using A* pathfinding, but by linecasting around him and basically "feeling out" the environment. So for example, when he "feels" or "sees" an obstacle, he turns to go around it. Here is an example of that: twitter.com/i/status/1089989454704582656 I would love to see you implement something like this :)
@Krebzonide4 жыл бұрын
I would like to make 2 ai attack each other. Is there a way to detect only the closest enemy so I don't have to run a large for loop for each unit?
@CodeMonkeyUnity4 жыл бұрын
If your enemies have Colliders you can use Pysics2D.OverlapCircle(); to locate all colliders near a certain position
@xplo89503 жыл бұрын
Is there a playlist encompassing all of the tutorials in order
@CodeMonkeyUnity3 жыл бұрын
Most of the tutorials are standalone, so just browse my video list and look for the topics that interest you
@chrisfarlee64963 жыл бұрын
So one thing i was wondering, is it better to use A* for path finding or a 2d NaveMesh?
@CodeMonkeyUnity3 жыл бұрын
A* is the algorithm, NavMesh uses A* to calculate the path. Do you mean Grid vs NavMesh? That depends on the structure of your levels
@chrisfarlee64963 жыл бұрын
@@CodeMonkeyUnity Good to know thank you! and i guess i did mean Grid vs mesh, sorry! i've only been working with unity for around 8 months and am still learning by day! I found a 2DNavMesh on Github that allows you to use unity's built in NavMeshAgent component directly and i've been using that for top down enemies, and i was just wondering if that's the most optimal way to implement it i guess!
@fv4202x Жыл бұрын
How do I make pathfinding for non grid based top down 2d games?
@CodeMonkeyUnity Жыл бұрын
Use NavMesh, although not sure if Unity's built in NavMesh supports 2D nowadays, I think there's an extension unitycodemonkey.com/video.php?v=atCOd4o7tG4 Or use something like the A* Pathfinding Project unitycodemonkey.com/video.php?v=46qZgd-T-hk
@Rejnols4 жыл бұрын
When i open the project in Unity i get a bunch of compile errors. Any idea why?
@CodeMonkeyUnity4 жыл бұрын
What compile errors? You're probably missing some packages
@Rejnols4 жыл бұрын
@@CodeMonkeyUnity A bunch of different ones. Just closed down the project and started working on something else. I downloaded the package files from your website, is there others i need to get somewhere?
@CodeMonkeyUnity4 жыл бұрын
@@Rejnols The project files contain all the code and assets but you still need to set up your project. If you see errors related to lights then you probably need to open the Package Manager and install the Universal RP
@thederpderp77583 жыл бұрын
Thanks!
@edwinmacias70383 жыл бұрын
hello, excuse me, in which tutorial did you make the code for "enemyMain"? excellent video by the way, thanks :)
@CodeMonkeyUnity3 жыл бұрын
That's not directly relevant to the AI logic, you can use any movement code and any animation system you want. For example I covered 2 character controllers here kzbin.info/www/bejne/eJfCZqR_qZ56qJo kzbin.info/www/bejne/o3u1lGyhgd15ic0
@edwinmacias70383 жыл бұрын
@@CodeMonkeyUnity I'm sorry, I got confused, I was referring to "gridPathfinding", I saw the list of pathfinding tutorials, but it seems to me that I skipped some, because the class was called only pathfinding
@Rabellois4 жыл бұрын
Could you do a tutorial about State Machines without enum? Using different classes for each state
@CodeMonkeyUnity4 жыл бұрын
I'm not a big fan of inheritance so I normally use simple enum state machines. However in Battle Royale Tycoon each Building has its own logic in a separate class and then within that class I have the normal enum state machine. So I might look into making a video on how that works.
@lucamassari6708 Жыл бұрын
Can you use the same script applied to different enemies that don't trigger the chasing together?
@CodeMonkeyUnity Жыл бұрын
What do you mean "trigger the chasing together"? Each script instance is separate, if you have 3 enemies and one starts chasing the player it won't affect the others, if the others are far from the player they will stay in their patrol state.
@jessenance88894 жыл бұрын
Wonder if it could be modified to my turn based game. Each move is limited to a certain range.
@schindoneer1983 жыл бұрын
Is there any way to do this wit the Ai from brackeys' tutorial?
@produccionesr71684 жыл бұрын
I would like to make a metal gear game, do you think this can be of use to me for that?
@CodeMonkeyUnity4 жыл бұрын
Sure, all AI is just expanding upon this same concept.
@sonicherores4 жыл бұрын
Can this logic be Used for 3d games :D? thanks for the great tutorials as always your essentials have helped me make stuff so much faster.
@caxopog4 жыл бұрын
Of course it can. U even can copy this code in 3D game and it may work even without additional code
@CodeMonkeyUnity4 жыл бұрын
Sure, the logic for handling the various states has no 2D or 3D dependency.
@sonicherores4 жыл бұрын
@@CodeMonkeyUnity Thank you again I thought as much but had no time to test it due to life up to what point in dev are we allowed to use your essentials incase of release. Nowhere near but goos to ask early thanks again for the wonderfull tutorials!
@evggg4 жыл бұрын
Hey! You are not using ShootingTarget state. All shooting locates in ChaseTarget state.
@CodeMonkeyUnity4 жыл бұрын
Yes, that state is meant to be a dummy state while the animation plays.
@emmesplaylists Жыл бұрын
Hi, I added the package to my project, but now I have a problem I don't know how to solve (I'm new to Unity): The type or namespace name 'LWRP' does not exist in the namespace 'UnityEngine.Experimental.Rendering' (are you missing an assembly reference?) [Assembly-CSharp]. Does anyone have a tip about what should I do?
@CodeMonkeyUnity Жыл бұрын
The Lightweight Render Pipeline has been since renamed into the Universal render pipeline, now it's under UnityEngine.Rendering.Universal;
@DoguethekillerYT4 жыл бұрын
Does it work for 3d games or in 3d projects?
@CodeMonkeyUnity4 жыл бұрын
Sure, there's nothing here limited to any perspective kzbin.info/www/bejne/aavbhZydn6-laJY
@DoraTheExplorerrr4 жыл бұрын
thank you hope its will work
@adeled88332 жыл бұрын
Thank you! I have made it looking less frizzy on frames (if there are many obsticles and the path is updated often) by making a square each time im setting a new roaming path around the roaming enemy x+ -5 y+ -5 (which is 11*11 possible values) ,and then checking if there are other enemies or obsticles, then substracting these grids out the 11*11 list, then choosing random one from the clean list
@billjohnson98804 жыл бұрын
If I make commercial game someday, can I use code samples or utility codes in Code Monkey?
@CodeMonkeyUnity4 жыл бұрын
Yup! Feel free to use anything you learn from these videos
@Roadis4 жыл бұрын
What is the best way to do this with ECS? I was thinking about adding components or deleting them when they should do other tasks. But how is the Performance for that?
@CodeMonkeyUnity4 жыл бұрын
Yeah I guess either adding/removing components or just a component with a State enum. Multiple components might be better since you can store state specific data. Adding/Removing components is extremely fast so unless you're changing state hundreds of times every frame it shouldn't be an issue.
@artemiymak83323 жыл бұрын
Hello, where I can look "previos video" with pathfinding system?
@CodeMonkeyUnity3 жыл бұрын
It's here kzbin.info/www/bejne/l524YWeeq99pgpY
@frazoni.3 жыл бұрын
@@CodeMonkeyUnity I was just about to ask the same, thanks for still answering questions even though the video is a bit "old". Cheers :)
@GhsT-th2gg3 жыл бұрын
is there a tutorial to make the attack system that you are using ?
@CodeMonkeyUnity3 жыл бұрын
I covered it here kzbin.info/www/bejne/nKaqgnmanbiDnZY
@IrvinMenezes4 жыл бұрын
I'm still lost, how does the float work as a measure of distance?
@CodeMonkeyUnity4 жыл бұрын
Do you mean the float reachedPositionDistance? It's just a value based on the unit scale of your objects. In my case, my characters are about 6 units tall so I set the value accordingly. If your characters are only something like 1 unit tall then change the value.
@anonymous-oq4fv4 жыл бұрын
hey code monkey i love ur videos but i had an issue and it is that when i put "private EnemyPathfindingMovement pathfindingMovement;" in the console puts me "The type or namespace name 'EnemyPathfindingMovement' could not be found" do you think you can help me with that i appreciate it
@CodeMonkeyUnity4 жыл бұрын
You dont have any class in your project named EnemyPathfindingMovement
@EVERYTHING-ey9em4 жыл бұрын
Just need this in 3d
@CodeMonkeyUnity4 жыл бұрын
The AI doesn't care what type of perspective you use kzbin.info/www/bejne/aavbhZydn6-laJY
@EVERYTHING-ey9em4 жыл бұрын
Thanks
@thomasbottino88584 жыл бұрын
Hello great tutorials u do big thanks they help Great. I bought some behavior designer and other but it was buggy and not as versatile as learning the basic that u offer us. One question about the patrolling state tho your map is very empty but how to deal with map with wall and obstacle where destination would be in the obstacle or even outside the map.
@CodeMonkeyUnity4 жыл бұрын
Add some pathfinding kzbin.info/www/bejne/l524YWeeq99pgpY
@ejazsafi47594 жыл бұрын
HEY! i made a minion with switch statement and nav mesh agent. and first case is destroy turret and after destory base. BUT when turret is destoryed it says "The object of type 'GameObject' has been destroyed but you are still trying to access it.". help me fix it how can i say ? if turret is destroyed switch case..?
@CodeMonkeyUnity4 жыл бұрын
What are you trying to do? Destroying the game object should be the last thing you do, first handle everything you need to do related to destroying the tower and only after everything is done do you destroy the game object
@ejazsafi47594 жыл бұрын
@@CodeMonkeyUnity i fixed it tnx! it was just basic syntax error... :)! but thank you!
@loot64 жыл бұрын
What if he's in a small room that he can't exit from, the random range will keep selecting locations out of his range...ie outside the room...?
@CodeMonkeyUnity4 жыл бұрын
You can easily apply some pathfinding logic on top of this system in order to identify walkable and non-walkable areas.
@loot64 жыл бұрын
@@CodeMonkeyUnity You didn't understand what I said, it's not about pathfinding. If he's in a room say 10 x 10 and he's plotting random distances to walk to between 20 and 50 he's just gonna constantly be finding locations outside of the room...
@CodeMonkeyUnity4 жыл бұрын
@@loot6 That IS Pathfinding. You get a random position, then check with your Pathfinding code to see if the position is reachable or too far. If it's not a valid position you generate another one.
@loot64 жыл бұрын
@@CodeMonkeyUnity With pathfinding you first generate a grid, it's important that your pathfinding algorithm only finds paths INSIDE that grid, otherwise you'd be wasting processing power checking loads of locations out of range. It seems the same would apply if trapped in a limited size room. In the example I gave you above, 80% of the paths found each time would be outside the room.
@terry-9 ай бұрын
Great!
@macadenmiles13334 жыл бұрын
Im confused, Where is the enemyPathfinding script that you made in a previous video? this is the most confusing part of the entire video
@CodeMonkeyUnity4 жыл бұрын
You can implement the Pathfinding in any way you want. Your AI should not depend on a specific Pathfinding implementation, it should be completely separate. I covered Pathfinding here kzbin.info/www/bejne/l524YWeeq99pgpY
@pythora41734 жыл бұрын
Does this work with 3D games as well?
@CodeMonkeyUnity4 жыл бұрын
Sure, there's nothing in this system that's specific to 2D
@pythora41734 жыл бұрын
@@CodeMonkeyUnity I downloaded the project files and put them in Unity, but it didnt work because there were so many errors. Fix?
@Chrischek894 жыл бұрын
Invalid Video ID on Project files link. Did you switch the location?
@CodeMonkeyUnity4 жыл бұрын
Seems I put the wrong link, here it is: unitycodemonkey.com/video.php?v=db0KWYaWfeM Thanks!
@nwoudochiobinna36733 жыл бұрын
Hello code monkey....do your tutorial work on 3d as well as 2d?
@CodeMonkeyUnity3 жыл бұрын
Yes, the AI doesn't care how the camera is set up
@nwoudochiobinna36733 жыл бұрын
@@CodeMonkeyUnity Thank you for replying...that's one of the things everyone loves about you...you still reply 😃
@cristiano48264 жыл бұрын
Create cards for the suggested videos. Thanks :)
@shuvi15652 жыл бұрын
What video is the pathfinding one?
@CodeMonkeyUnity2 жыл бұрын
Here it is kzbin.info/www/bejne/l524YWeeq99pgpY
@hamzamusani55003 жыл бұрын
How does one set an instance 6:15
@CodeMonkeyUnity3 жыл бұрын
It's set on Awake()
@hamzamusani55003 жыл бұрын
@@CodeMonkeyUnity thank you
@belddap89093 жыл бұрын
Can I use machine learning for AIs?
@CodeMonkeyUnity3 жыл бұрын
Sure! kzbin.info/www/bejne/sIGphmZmqcesgdU
@TheTrolderia3 жыл бұрын
In a 2d top down game, how do i make my AI walk random between 1-5 sec and then stop for 1-3 sec, and then walk again? :)
@CodeMonkeyUnity3 жыл бұрын
Add a simple timer, when you reach the position change the state to start counting the timer, when timer is done go back into the patrol state and back into the next position.
@TheTrolderia3 жыл бұрын
@@CodeMonkeyUnity Thanks for quick respons - But what kind of code do i need? It's a random position, so he dosen't reach it? Is it like when he walked beetween 1-5 -X or -Y pos, change pos?
@BlastGamer77 Жыл бұрын
The roaming code given in the first part of this video doesn't work. The EnemyPathfindingMovement script will always result in a NullReferenceException on the "pathVectorList = GridPathfinding.instance.GetPathRouteWithShortcuts(GetPosition(), targetPosition).pathVectorList;" line, even if the code is copied one to one from what you have in this video and even if the pathVectorList is made beforehand (As to not make it null). The error only happens in play mode but it prevents the whole roaming script from working properly.
@concov3000 Жыл бұрын
I'm getting the same issue when it come to the EnemyPathfindingMovement. Visual Studios tells me that the namespace couldn't be found :( Any fix to this issue?
@CodeMonkeyUnity Жыл бұрын
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw Maybe you don't have the GridPathfinding set up, maybe your unit is off-grid, maybe theres no path to that point
@BlastGamer77 Жыл бұрын
@@CodeMonkeyUnity I did. I tested all three parts and the one that returned a NullReferenceException is the GridPathfinding.instance.GetPathRouteWithShortcuts(GetPosition(), targetPosition) part. But I have GridPathfinding setup. In fact I got it directly from the files given for this lesson on your website.
@BlastGamer77 Жыл бұрын
@@CodeMonkeyUnity Are you going to answer my comment? Either your code doesn't work, or you failed to include critical information in your own tutorial.
@BlastGamer77 Жыл бұрын
@@CodeMonkeyUnity Ok I have tried literally everything; your code does not work. I fixed my initial issue but now the object refuses to move even when using your exact code. The export on your website does not work; there's no scene and no way to test it. This entire tutorial is useless.