Modular Character System in Unity (Move, Attack, AI, Pathfinding)

  Рет қаралды 84,414

Code Monkey

Code Monkey

4 жыл бұрын

🌍 Go to admix.in/ and Start Earning Revenue in under 24 hours!
✅ Get the Project files and Utilities at unitycodemonkey.com/video.php...
Let's make a Modular Character Controller where we can build Modules (Movement System, AI, Pathfinding) and compose them to make our Character Controller!
This is also an excellent exercise in learning how to write clean code.
This video is sponsored by Admix
A* Pathfinding in Unity
• A* Pathfinding in Unity
Pathfinding in Unity DOTS (Insane Speed!!!)
• Pathfinding in Unity D...
Make Awesome Effects with Meshes in Unity | How to make a Mesh
• How to make a Mesh in ...
If you have any questions post them in the comments and I'll do my best to answer them.
🔔 Subscribe for more Unity Tutorials / @codemonkeyunity
See you next time!
📍 Support on Patreon / unitycodemonkey
🤖 Join the Community Discord / discord
📦 Grab the Game Bundle at unitycodemonkey.com/gameBundl...
📝 Get the Code Monkey Utilities at unitycodemonkey.com/utils.php
#unitytutorial #unity3d #unity2d
--------------------------------------------------------------------
Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.
I've been developing games for several years with 7 published games on Steam and now I'm sharing my knowledge to help you on your own game development journey.
You can see my games at www.endlessloopstudios.com
--------------------------------------------------------------------
- Website: unitycodemonkey.com/
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Пікірлер: 246
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Let's make a Modular Character Controller where we can build Modules (Movement System, AI, Pathfinding) and compose them to make our Character Controller! 🌍 Go to admix.in/ and Start Earning Revenue in under 24 hours! 👍 Using the tool helps support the channel!
@arsenbabaev1022
@arsenbabaev1022 4 жыл бұрын
is it good idea to use it in RTS ? i feel like i need around 10 modules for all behaviors moving units garher res. atk.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
@@arsenbabaev1022 It would be very useful in an RTS. Your Gatherers and Soldiers would share the same Movement and Animation modules with a different Logic module.
@nxd2877
@nxd2877 4 жыл бұрын
i will be glade if the next tut about trigger particle system with 2d trigger by code
@Norbingel
@Norbingel 4 жыл бұрын
Showing the end result of what the tutorial will accomplish right at the beginning of the video so people know whether it's something they want is something every tutorial should do. That alone would get me subscribed if I weren't already.
@CCV334
@CCV334 3 жыл бұрын
I love the format of his videos they jump into the tutorial right away, no wasted time!
@mcgeufer
@mcgeufer 4 жыл бұрын
I came for the tut but stayed for the add. That's actually something I was looking for a long time. Integrating adds in a game instead of disturbing the players expieirence all the time.
@raghulponnusamy9034
@raghulponnusamy9034 4 жыл бұрын
you are awesome .currently I'm separating visual and core logic using events that made code very easy to use. Thanks for all the videos.
@TripleCreeper3
@TripleCreeper3 2 жыл бұрын
i bought 2 courses and saw around 20 tutorials to find finally one that is oriented to changing movement, weapons, etc... Much thanks!!!
@mehmedcavas3069
@mehmedcavas3069 4 жыл бұрын
Ohh yes. The most important thing of solid code. This is by far the best tutorial for clean code and also shows how to add multiple scripts on one go and how to interact with them 😊😊
@janmarcbaniqued7612
@janmarcbaniqued7612 3 жыл бұрын
This is amazing!!! I didn't know we can use interfaces like that. This changes so so much thank you!
@tiagodarkpeasant
@tiagodarkpeasant 4 жыл бұрын
finally the part i wanted to learn, making simple scripts is easy, using all of them in the same object not so much
@oyaguni961
@oyaguni961 2 жыл бұрын
Not going to lie, I love you for introducing me to interfaces. Thank you SO very much for your invaluable content!
@eierschaedl
@eierschaedl Жыл бұрын
i love the sound of your keyboard. so satisfying.
@FICHEKK
@FICHEKK 4 жыл бұрын
Amazing and very helpful video! Please do more of these "good-design" and "architecture" videos!
@paulblart7378
@paulblart7378 2 жыл бұрын
Super helpful video! I'm making a defense game and I want a lot of my scripts (target finding, attacking, AI logic, etc.) to be usable by towers, units, and enemies, so a modular system is crucial. That way, I can easily create different behaviors by swapping out components. Thanks a lot!
@benjaminsnow5095
@benjaminsnow5095 4 жыл бұрын
Absolute mad lad! You are truly epic!
@justinwhite2725
@justinwhite2725 4 жыл бұрын
Thanks for sharing admix. I know it’s probably sponsored but it’s highly relevant. Unfortunately most of my games are fantasy and it doesn’t seem appropriate, but I love the idea.
@deadly_artist
@deadly_artist 4 жыл бұрын
Share your opinion on that, but I bet it would be funny for players if they were to find ads in cities, towns, sci-fi ships or dungeons or whatever, especially where it doesn't fit at all - as long as it isn't overbearing
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yeah it's a sponsor but the product is excellent, if I did free games I would certainly use it. Banner ads are always awful.
@kruth6663
@kruth6663 3 жыл бұрын
This is what I'm looking for. Thanks!
@nerdact5920
@nerdact5920 3 жыл бұрын
Im relearning c# right now and i feel like i understand the importance of this so much better now. Great video which i couldnt appreciate before the way i do now. And I'll probably appreciate it at some later stage even more :D
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
I'm glad you found the video helpful!
@digitalfortress1208
@digitalfortress1208 3 жыл бұрын
Dude you are awesome. This is good stuff.
@personanongrata4419
@personanongrata4419 4 жыл бұрын
Hey codemonkey - do you have any plans on covering the stuff in between this and your past A* pathfinding video? I've been following along and am a little lost because it seems like there are a lot of changes from the PathNode/Grid video and this one, with binary trees and all the other pathfinding scripts. thanks!
@tigransahakyan2840
@tigransahakyan2840 4 жыл бұрын
Great as always Also it would be really great to see how did you make you animation system in details cause there is so many things in animation system.
@danielvillalba4457
@danielvillalba4457 3 жыл бұрын
Hi, great video, yes I would like to see a video dedicated to interfaces and how to explore their benefits in Unity, I use them a lot in web development in order to enable composition and decoupled designs, I have been using them in Unity for a couple of years during my exploration but I’m sure you have lots of cool implementations.
@PatagonianDuck
@PatagonianDuck 3 жыл бұрын
If you experience that Movement is relative to distance clicked (faster if mouse farther away) then check to see that the Z axis in all components is the same or 0 for 2d. Also check prefabs for this
@filipgawlik3259
@filipgawlik3259 4 жыл бұрын
Please, make a video about interfaces. By the way - do You recommend using Scriptable Objects?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Sure, they can be an insanely useful tool. A lot of official unity things, (like HDRP, URP, Shader Graph) use Scriptable Objects to organize their data.
@tiagodarkpeasant
@tiagodarkpeasant 4 жыл бұрын
i use for example to make characters, so i change one object and that changes both the controlable character and any interface related to the character, like for example changing the hp in the scriptable object so it affects the character selection interface and the actual hp of the unity i can also have different prefab paths that i put int the scriptable object so depending of the scene the same character could be diferent gameobjects, like overworld object, turn battle object, water level object i am making a pokemon like rpg, and in the scriptable object i list all the skills the species can learn, while saving the moves they know in another class that i use for save games
@extremeliving592
@extremeliving592 Жыл бұрын
You sir, are a genius...
@zekiozdemir420
@zekiozdemir420 3 жыл бұрын
Thanks for making these videos
@Moon-cr4mu
@Moon-cr4mu Жыл бұрын
this is so useful, thanks!!
@oldcat1790
@oldcat1790 4 жыл бұрын
Interfaces video sounds interesting.
@user-hz4tc2pf3x
@user-hz4tc2pf3x 4 жыл бұрын
Could you make a video about stuff that isn't considered when talking about tutorials? (E.g.: resolution, build bugs, optimizing code, pixel perfect camera (seriously who knows how that works?), polishing and just more advanced and further-into-development tutorials)
@mohameddabbour6961
@mohameddabbour6961 4 жыл бұрын
Yes! please make video about interfaces
@ghiancarlostan8730
@ghiancarlostan8730 2 жыл бұрын
is this a good way to create a weapon system? like i should create different scripts per unique weapons based on their attack patterns?
@MaGiStReall
@MaGiStReall 4 жыл бұрын
Love your videos, keep it up! Btw, will there be any multiplayer tutorials?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yeah I've been meaning to look into the state of Unity DOTS NetCode, hopefully soon!
@nikolasxyinidis7514
@nikolasxyinidis7514 3 жыл бұрын
Thank you soooo much this is very helpful
@smallg9109
@smallg9109 4 жыл бұрын
thanks, i didn't know about interface scripts :)
@supergalaxysam
@supergalaxysam 3 жыл бұрын
Your tutorial is great; It's very easy to follow along and straight to the point. I know this is meant more for a 2D controller, but I tried to follow it to create a modular controller for 3D games. What would I use in replacement for the code presented within the "PlayerMovementKeys.CS" script to get "W" and "S" to move forward and backward in a 3D space? I am also running into a compiling error with the "PlayerMovementMouse.CS" script because the game is unable to recognize "(UtilsClass.GetMouseWorldPosition());". Unity version is 2020.2.6f1 with VisualStudio 2019.
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
The easiest thing is just to swap Y movement for Z movement. UtilsClass is part of my utilities, here's how you get the world position kzbin.info/www/bejne/Zpu3gX6waMyUatk
@magictimm4090
@magictimm4090 4 жыл бұрын
Why "public const int WALL_WEIGHT = 56000;" in the GridPathfinding class? Must i reduce the 56000 if I reduce the nodeSize ? The Pathfinding in my Project has some problems on edges of objects.
@LoopyWolf
@LoopyWolf Ай бұрын
All this code, and a great tutorial.. Support!
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
Thanks for the super thanks! I'm glad you found the video helpful!
@LoopyWolf
@LoopyWolf Ай бұрын
@@CodeMonkeyUnity While I have your attention, quick question.. Is the code provided for this video what is used in the RTS tutorial? ps I sent you a donation. I hope you got it!
@CodeMonkeyUnity
@CodeMonkeyUnity Ай бұрын
hmm it's been quite a long time since I made this and that video so I'm not 100% sure but since they came out at roughly the same time I think so. For that RTS tutorial I focused just on the selecting characters logic, so the movement is super simple.
@arcday4281
@arcday4281 4 жыл бұрын
You're cool! No doubt you will have more and more subscribers and support, the main thing is not to stop feeding us lessons ))) . I only understood half of it, but it was enough to watch with interest...
@andrewshandle
@andrewshandle 4 жыл бұрын
This is great.
@cbr9731
@cbr9731 3 жыл бұрын
I have the problem in direct movement with the mouse, where the transform component does not fit into the mouse position at the moment originating as a vibration.
@mehmedcavas3069
@mehmedcavas3069 4 жыл бұрын
can you also show us how you combined it with your animation script? a simple one with walk, idle and attack would be enough
@Fyres11
@Fyres11 2 жыл бұрын
Great idea. Could it be used in a level system? I mean activating a script when you reach a specific level? Would it be a good idea to put all the modular scripts onto the player and use a level up script to enable/disable them depending the player level?
@SebyGamerZROZ
@SebyGamerZROZ 4 жыл бұрын
Nice work ! ✓
@PatagonianDuck
@PatagonianDuck 3 жыл бұрын
Add This line if (Vector3.Distance(movePosition, transform.position) < .0001f) moveDir = Vector3.zero; // Stop moving when near to avoid sprites shaking when finish moving. This was not included in the video and instead I found it in the game files on his website.
@zamilamin3646
@zamilamin3646 3 жыл бұрын
where to add this code
@PatagonianDuck
@PatagonianDuck 3 жыл бұрын
@@zamilamin3646 I'm sorry it's been so long, I forget
@TheBigHeinousAnus
@TheBigHeinousAnus 2 жыл бұрын
@@zamilamin3646 it's in the MovePosition class... also for anyone else reading this, if you still get shaking after adding this line, make sure your Rigidbody2D has the correct gravity settings configured. I added that component after adding the scripts and spent a few hours being really confused as to why my RTS units were still acting like they had too much coffee...
@gfulpakwuli3799
@gfulpakwuli3799 2 жыл бұрын
Really awesome, I am using similar system, of course at runtime time all this components would be enabled/disabled instead of added/removed. I am curious about the light around your character. Is it a light, or simply a sprite with transparency, what is an optimized way to do it?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yup it is a 2D light, I never tried pushing the 2D Lighting system to it's limits but I never had issues with it.
@Palutena618
@Palutena618 4 жыл бұрын
Great video, as always! I've come across an issue that didn't pop up in your video: When trying to make a character or any object move via the mouseinput, they move towards the point but then overshoot it due to the movespeed jumping back and forth around the destination spot. If I reduce the movespeed, the issue is less pronounced but it still does that for quite a few loops. Also, if I don't normalize the moveDir vector3, there's no jittering at the destination but then the movement is not linear and goes way too fast. Am I missing something here? It's a simple issue but I can't figure out how to solve it in this setup.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Usually you do a distance check to test if it reached the position, and if your character is teleporting then it sounds like its moving more each frame than the distance you're testing for. Either increase the amount that you're testing or test the distance before and after moving, if it's further after than before then you've reached your destination.
@MatthewChowns
@MatthewChowns 4 жыл бұрын
Could this sort of modular approach be used with DoTs? ie. swapping between two different systems, or enabling/disabling certain features while testing?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yup, DOTS is already super efficient at only running Systems if there are Entities that match the Query.
@waltuh08
@waltuh08 4 жыл бұрын
you are the best thank you
@MrAmix2
@MrAmix2 4 жыл бұрын
You focused on manually changing the scripts, but is it possible to do it during runtime? For example is enemy sees player it switches AI script to chase him and after a while returns back to default state, by enabling / disabling components. Will it work? Great video :)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yup, that's pretty much what I did when I made the Top Down Shooter game kzbin.info/www/bejne/e6rbZHicptaZg9k When the enemies get spawned they are static, essentially they have their logic and move components disabled while the spawn animation finishes.
@victrolaface
@victrolaface 4 жыл бұрын
If I wanted to separate the player data into a scriptable object i.e. speed, health, strength etc. What is a good approach adhering to modularity? I assume make a InitializeData component that serializes the scriptable object, then each subsequent component, i.e. HealthComponent sets it's field "health" to the InitializeData component's scriptable object's health value. My concern is the usage of get/require component, performance, and coupling of data. Is it better to have a public field in each component for the scriptable object or is my approach above more efficient? Appreciate your feedback.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Having a central script holding all your stats would be a good approach. It would make your scripts tighly coupled with your data script but that's not necessarily a problem. Achieving perfect modularity and code decoupling is a good goal to have but don't let that blind you from your primary goal of actually making your game, sometimes more modularity will actually increase complexity.
@KalponicGames
@KalponicGames 3 жыл бұрын
this tutorial is amazing :). You really like top-down games. 90% tutorials you have are top-down
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
Yup I'm a big fan of Top Down 2D and with that perspective I can showcase pretty much any system possible!
@KalponicGames
@KalponicGames 3 жыл бұрын
@@CodeMonkeyUnity is email a good way to contact you? The one on youtube?
@MalikenGD
@MalikenGD 4 жыл бұрын
Is the modularity shown here good for ECS (not necessarily DOTS)? Is this a great example of subbing out components or systems?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Hmm yes in the sense that ECS is all about Components so you can have a MoveSimple IComponentData and a MovePathfinding IComponentData However I don't think ECS works with interfaces since that requires type conversion.
@keelanbowker-obrien2222
@keelanbowker-obrien2222 4 жыл бұрын
Instead of grabbing rigidbody for move velocity could you grab game object so that move velocity could interact with things like lights?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
The MoveTransformVelocity script moves the transform directly without any Rigidbody
@kerduslegend2644
@kerduslegend2644 25 күн бұрын
this is a great tutorial. although i have a several question, for example "should you reparate animator logic with a movement logic?"
@CodeMonkeyUnity
@CodeMonkeyUnity 24 күн бұрын
Personally I like to keep logic and visuals as separate as possible, so normally I do separate the movement logic from the animator logic. Although it also depends on the complexity of your project, if it's something simple you can just keep them together. But on complex things I make a separate class that just handles the animation parameters.
@MB-eq9ew
@MB-eq9ew 2 жыл бұрын
Using get component in update , is same with getting in start but way more optimization problem right ?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yes I only did it that way for the video to demonstrate the system while hot swapping. For a final game you would only do it once on Start
@utkugokalp3179
@utkugokalp3179 4 жыл бұрын
Great video as always! But why did you chose to make an IMovementVelocity instead of an abstract class? Because I would probably choose to create an abstract class in order to reduce code coupling since both of the classes have very little different code. Other interfaces make sense since the actual codes implemented are very different from one another but I really don't understand the purpose of using interfaces for very little code changes, it just seems like code coupling to me.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Usually an interface is meant for exposing certain behaviour whereas an abstract class is meant to represent a more complete object, that's why interfaces are public and have no fields. I don't want MovementVelocity to be an object, I want it to represent a specific behaviour. Interfaces also let you have multiple implemented in one class, so if you had a lot of modules you could create more complex modules that group more simple behaviour.
@utkugokalp3179
@utkugokalp3179 4 жыл бұрын
@@CodeMonkeyUnity Thanks :) I've been trying to understand the difference since like forever :P
@gdk870
@gdk870 3 жыл бұрын
@@CodeMonkeyUnity This is the best argument read yet for using an Interface vs. Abstract class. Good job.
@danielcorzo7498
@danielcorzo7498 3 жыл бұрын
Hi, I have some questions: Just how modular should I make a character (or anything)? I mean, if I wanted to create something like a character in a RPG (say Skyrim), will I end with dozens of different scripts attached to the character by taking this approach? Also, if I wanted to create my own components (like a Rigidbody), how modular should I make them? Thank you
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
That depends on your specific scenario. Modularity can be a huge help but it can also be bad, it's just another tool. Make a quick prototype and see which method works best.
@GamernetsLP
@GamernetsLP Жыл бұрын
I am using the MoveTransformVelocity script that you make here together with the mouse position direct movement and the character jitters very hard once they reach their target location. How can I fix that?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Sounds like you need to define some stopping distance and stop it when it gets close, it will never 100% reach the perfect mathematical correct position.
@mohokhachai
@mohokhachai 8 ай бұрын
Professional tutorial
@techbytefrontier
@techbytefrontier 4 жыл бұрын
Great video, please make one about your animation system.. sync animation in unity sometimes can be very hard for me..
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
It's based on dynamically modifying meshes kzbin.info/www/bejne/Z2LGaqWNh9SngJo
@andylockhart257
@andylockhart257 4 жыл бұрын
Yes please on Interfaces!!
@terry-
@terry- 4 ай бұрын
Great!
@keetee-ei3er
@keetee-ei3er Жыл бұрын
Awesom, thansk! How is that you dont need to add IMoveVelocity interface script to player object inspector and it still works?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
You don't attach an interface directly to a game object, you attach some MonoBehaviour that implements that interface
@keetee-ei3er
@keetee-ei3er Жыл бұрын
@@CodeMonkeyUnity Awesome, thanks
@pabloandresherreracantilla9177
@pabloandresherreracantilla9177 4 жыл бұрын
Not sure if I'm doing something wrong. When I assign the MoveTransformVelocity script to my player, it starts colliding with other objects. Any ideas?
@papatomicjusz
@papatomicjusz 3 жыл бұрын
Any progress on that issue?
@dannykay4649
@dannykay4649 4 жыл бұрын
Please do a dedicated video on interfaces!
@jimmyfitzsimmons7170
@jimmyfitzsimmons7170 Жыл бұрын
At 12:11 I've done the exact setup as you did but with the MoveTransformPosition Script activate my player can't pass through the wall. But if I remove the rigidbody or turned it into a Kinematic Rigidbody he is able to go through the wall. But I didn't see you touch the rigidbody component at all so what am I missing ?
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
That behaviour is sort of dependent on your framerate. Basically on every Update the transform is being forced inside the wall, but then on the FixedUpdate the Rigidbody tries to move the object away from the wall. So you're probably not missing anything, just running the game at a lower framerate which makes it more "difficult" for the Update code to force the transform inside the wall
@hidingdissident
@hidingdissident Жыл бұрын
@@CodeMonkeyUnity whats your framerate? I am running this with 160 fps and I am bouncing off the wall when using the MoveTransformPosition script.
@MrREALball
@MrREALball 4 жыл бұрын
Can you make the same thing using dots? Im still not used to thinking in dots terms, so maybe its extremly easy to do, but I cant think of a good way to do so.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
DOTS is already component based so the core logic works the same however I don't think DOTS supports Interfaces so thats the one key difference. But you can already have lots of systems that each do their own behaviour depending on the component on the entity.
@washynator
@washynator 4 жыл бұрын
Correct me if I'm wrong, but you are not supposed to use GetComponent inside of Update, right?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yes correct, doing GetComponent on every Update is not good for performance. However in this case I did it that way so that I could demo swapping out the modules in real time, if I had cached them, like you should do in a proper game, it would give me a NullReferenceException when changing the module.
@washynator
@washynator 4 жыл бұрын
@@CodeMonkeyUnity Yeah, well that does make sense. Awesome video still! Keep up the great work!
@markedforstrike
@markedforstrike 4 жыл бұрын
@@CodeMonkeyUnity maybe we can use variable and check if component available or not. Also once I saw smth with instances, not sure about it, but script was called via ScriptName.Instance.MethodName(); P.S. Hello from Russia, Mr. Worldwide UPD Sorry, it was just public static
@magictimm4090
@magictimm4090 4 жыл бұрын
@@CodeMonkeyUnity Have you heard about this? since 4.6 GetComponent in Update is not a problem for performance. www.reddit.com/r/Unity3D/comments/4xptnk/a_c_generic_class_that_wraps_getcomponent_caching/d6hj3iy/
@quinclarke2331
@quinclarke2331 2 жыл бұрын
Hi i' having a problem with the pathfinding on click, as i followed the grid video generic grid video and also A* pathfinding video. However in none of them is a method called instance or GetRouteWithShortCuts created and i'm confused as too where they've come from. If anyone knows where they're from or if i can replace them with something else as i'm a bit lost right now. Thank you!
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
The pathfinding that I covered in that video is the simplest thing possible, in most videos where I use pathfinding I'm using a more advanced version of the algorithm. That function simply makes shortcuts where the path is unobstructed, so instead of the unit zig zagging when moving diagonally it just goes straight until it finds a wall
@llamagame8817
@llamagame8817 Жыл бұрын
@@CodeMonkeyUnity I’m guessing “the more advanced version” is covered in your pathfinding with DOTS(insane speed) tutorial? Thanks
@magecode9585
@magecode9585 4 жыл бұрын
very very cool
@kylemedina5112
@kylemedina5112 2 жыл бұрын
Notes: 11:16 Using Interface script for the ability to switch between scripts(that inherit from the Interface class)
@ericf.2267
@ericf.2267 4 жыл бұрын
Would there be any benefits/drawbacks to doing something similar through events, instead of interfaces? I would assume you could make a similar modular character system, but using different architecture (maybe you could address that in an interface video, which I would be totally for). Keep up the good work man!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
What do you mean through events? Events just broadcast that something happened, they dont "hold" logic. I guess maybe you could have some base classes and different modules would extend those base classes in different ways and fire off events when something happened? That would be a very strange messy architecture
@ericf.2267
@ericf.2267 4 жыл бұрын
In a lot of your videos you use events to also pass along information using delegates and eventhandlers. In this video you use the interface to set up a "contract" about what information gets passed to an agreed upon method (like vectors or positions). I imagine you could have a class set up events that could send along information to subscribing components, which would still "hold" the logic. So you could set up an input class that would pass information to subscribers when keys were pressed or when a mouse was clicked (with the subscribing components handling that even information any way they wanted) Hope that makes more sense!
@grachamoncha
@grachamoncha Жыл бұрын
At 15:37 you cut away then you have a system called GridPathfindingSystem at the top. Where did you get this? How can I get it? A quick Google doesn't yield any definitive results.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
That's my own pathfinding system, it's not a Unity built-in thing so that's why you can't find it. I covered the A* Pathfinding algorithm in detail here unitycodemonkey.com/video.php?v=alU04hvz6L4
@danielcorzo7498
@danielcorzo7498 3 жыл бұрын
Hi, when I hit play in Unity I can’t see the characters, I only get to see pink squares instead of the right sprites, I know this is usually because Unity can’t find the appropriate shaders but the only thing I modified was to change “using UnityEngine.Experimental.Rendering.LWRP;” to “using UnityEngine.Experimental.Rendering.Universal;” so I could get rid of some errors messages. I’m also getting these two warnings: “The referenced script on this Behaviour (Game Object 'Main Camera') is missing!” “The referenced script on this Behaviour (Game Object 'PostProcessingVolume') is missing!” Of missing scripts that were attached to the Main Camera and the PostProcessingVolume Game Objects, any ideas? Thank you
@michaeljung3251
@michaeljung3251 3 жыл бұрын
Maybe you don't need this anymore but for anyone else - the pink squares issue. After installing all the required packages - Cinemachine, Universal RP, ProBuilder, etc., go to Assets>_>Stuff>Textures>UnitSpriteSheets and for the two pink items, the .mat files, change the Shader type to Universal Render Pipeline > 2D > Sprite
@dodo5045
@dodo5045 Жыл бұрын
why cant u have 2 scripts using the same interface with 1 disabled, u have to remove the other component completely?
@Semaj0z
@Semaj0z 4 жыл бұрын
Why don't u use getaxis for the player wasd movement
@supapaw
@supapaw 5 ай бұрын
6:52 actually it has two purposes: to move the rigidbody AND play the animation :)
@johngalt200
@johngalt200 2 жыл бұрын
What are the shortcuts from GetPathRouteWithShortcuts?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
It creates paths with direct waypoints instead of stair-like paths, moving diagonal for a long distance instead of up-right-up-right-up-right
@AstraGamesStudios
@AstraGamesStudios Жыл бұрын
Hey @CodeMonkey ! i was wondering if this code will still work (and with your RTS click and command units video) in top-down 3d? Just like the game you make from the Unity co-op project.... the one with the pigs. 🐷 Thanks!
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Sure, all this is doing is moving to a position, that position can be on the XZ plane or XY, getting the mouse position is the big difference unitycodemonkey.com/video.php?v=0jTPKz3ga4w
@AstraGamesStudios
@AstraGamesStudios Жыл бұрын
@@CodeMonkeyUnity sweet! thanks! btw, if you did a video on a top-down 3D RTS game that would be really cool! Have a good one!
@AstraGamesStudios
@AstraGamesStudios Жыл бұрын
@@CodeMonkeyUnity sweet! thanks!
@ronnid8837
@ronnid8837 3 жыл бұрын
Hey Code Monkey, how would you implement a state machine pattern into a design like this? Say for example, the player should move differently when in inAir_State or in onGround_State? Thanks and nice tutorial as always!
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
I covered a basic state machine here kzbin.info/www/bejne/mpOTfIqPlryZm68 However in your case if you just want to handle movement with a different speed then a simple boolean isGrounded would be a better approach
@ronnid8837
@ronnid8837 3 жыл бұрын
@@CodeMonkeyUnity Thanks, will have a look at that. It's a bit more complex I guess.. I got a bird and he should be able to: - walk on the ground(GroundState) - jump from ground(InAirState) - glide while InAir(GlideState) And all states should treat input differently. I'm stuck on how to implement this.. Have you got an idea how to deal with this?
@Ashley-xb1dz
@Ashley-xb1dz 3 жыл бұрын
@@ronnid8837 It seems like you would just trigger different states, walk (arrow keys) jump (space bar) double jump/glide (press space bar twice) ...
@theashbot4097
@theashbot4097 11 ай бұрын
with the mouse input and move position it makes the character go past the target then I get the glitchy movement where the unit never hits the way point. how did not not get it?
@CodeMonkeyUnity
@CodeMonkeyUnity 11 ай бұрын
Depends on how fast you move it and how tiny is your reachedPositionDistance. IF you move too fast and you have too tiny distance it might constnatly jump back and forth because it never quite gets there
@Michal005
@Michal005 4 жыл бұрын
Can you make video on storage or chest compatible with your inventory???
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
The Inventory is just a class so it can live wherever you want, you can use it as a UI Element or open/close a window by touching a Chest. The inventory itself doesn't really need to change.
@tonyclx
@tonyclx 3 жыл бұрын
​ @Code Monkey I used it in Unity 2018 and 2019 still getting this error CS0234: The type or namespace name 'Universal' does not exist in the namespace 'UnityEngine.Rendering' I am a beginner. I really appreciate your help. All I am trying is to run the exact project you made. I have added nothing to it..thanks
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
You need to install the Universal RP from the package manager
@lucasgiffuni6267
@lucasgiffuni6267 4 жыл бұрын
Hi, can you do a tutorial of melee attack system with the sword?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yeah I covered it here kzbin.info/www/bejne/d4nOkqSNaKpshas
@Bartek-6772
@Bartek-6772 Жыл бұрын
How you get grid for pathfinding? You use GridPathfinding.Instance is it automatic calculating grid or you just defined it manually? (i am only interested in method not how script works)
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
It's using A* Pathfinding which I covered here unitycodemonkey.com/video.php?v=alU04hvz6L4
@Bartek-6772
@Bartek-6772 Жыл бұрын
​@@CodeMonkeyUnity i know that but how do you set not walkable area? In video that you linked you set the grid at runtime. But in this video it looks like automatic process. You just use GridPathfinding.Instance... without setting the grid before start. Do you have script that sets it manually or you just didn't show setting grid in video?
@FergoniusYeet
@FergoniusYeet 3 жыл бұрын
Is there a way to implement this pathfinding with an isometric tilemap?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
You can have isometric visuals while keeping a flat logic grid. Just need to do calculations when converting positions into grid positions.
@umairmalik6480
@umairmalik6480 4 жыл бұрын
Please make a video on interface also
@adeled8833
@adeled8833 2 жыл бұрын
It didnt go through the wall, my player rotated when touched walls like crazy for some reason with the first (rb) method
@abuUthmani
@abuUthmani 2 жыл бұрын
7:28 isn't GetComponent in update methods a bad way to get a reference to the script you want? it is said to be expensive and not recommended, i think you should also mention that in your tutorials.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yes, it is only used in the demo to showcase hotswapping the components while the game is running. In a proper game you would cache the component.
@LekoKeller
@LekoKeller Жыл бұрын
Can someone help me? I'm having an error with the MovePositionPathfinding script I think the problem is at the line "pathVectorList = GridPathfinding.instance.GetPathRouteWithShortcuts(transform.position, movePosition).pathVectorList;" The error I'm getting is: NullReferenceException: Object reference not set to an instance of an object Thanks in advance
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
@Michal005
@Michal005 4 жыл бұрын
How to change this scripts by code???
@tiagodarkpeasant
@tiagodarkpeasant 4 жыл бұрын
do you have gravity set to 0 by default ?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yes I set it to 0 since I'm working in a Top Down perspective.
@nbdy296
@nbdy296 4 жыл бұрын
with the direct mouse movement, my character stutters around the target postion instead of just stopping... any clues why ?
@asemon007
@asemon007 4 жыл бұрын
I'm suffering the same problem
@nbdy296
@nbdy296 4 жыл бұрын
@@asemon007 I worked it out eventually after watching the rest of the vid. At 15:45 when he shows the pathfinding movement he uses a threshold to determine when to stop movement (line 26). I used that in the direct movement too and it fixed it.
@asemon007
@asemon007 4 жыл бұрын
@@nbdy296 Thanks man!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Yes, depending on how fast your unit moves you need to adjust the distance for it to stop moving.
@byeileft894
@byeileft894 4 жыл бұрын
Can u do these coding but with good 3d models cause I want to try to make a pokemon based game
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Pretty much all the code works in 3D and there are only some small changes needed. Instead of using Rigidbody2D use Rigidbody. Instead of SpriteRenderer use MeshRenderer
@kiss_fish
@kiss_fish 3 жыл бұрын
Im a bit confused - how does the pathfinding work in this project - all your pathfinding tutorials work with grids but here you just have objects in a scene? Or do you have a tutorial covering this?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
There is a Pathfinding grid being used, it's just not visible.
@kiss_fish
@kiss_fish 3 жыл бұрын
But how did you make the nodes around the wall unwalkable
@kushovu
@kushovu 4 жыл бұрын
Where is the link to the video that u told at 5:22, the Animation system, i cant find it
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
It's this one: kzbin.info/www/bejne/Z2LGaqWNh9SngJo
@kushovu
@kushovu 4 жыл бұрын
@@CodeMonkeyUnity got this haha thx for all!
@SanderVerveer
@SanderVerveer 24 күн бұрын
Would it be posible to post me "Character_Base " content, stuck on the part that is untill now not in the video, with kind regards. Sander
@CodeMonkeyUnity
@CodeMonkeyUnity 23 күн бұрын
That class is just responsible for rendering/animating the character, you can use whatever animator controller you want, it's not directly related to making a modular character system
@shanjohnkj6851
@shanjohnkj6851 3 жыл бұрын
Please explain how moveposition - transom. Position works its been long time searching for crrt answers
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
It's simple vector math to get the direction, you do targetPosition - currentPosition and you get the resulting vector between those two points.
@shanjohnkj6851
@shanjohnkj6851 3 жыл бұрын
@@CodeMonkeyUnity brooo thankyouuu
@daltonguthrie3544
@daltonguthrie3544 2 жыл бұрын
Anybody else having issues with the GridPathfindingSystem in the MovePositionPathfinding script? Is there something I need to do in order to have Unity register that Namespace? Assets\Scripts\PlayerControls\MovePositionPathfinding.cs(4,7): error CS0246: The type or namespace name 'GridPathfindingSystem' could not be found (are you missing a using directive or an assembly reference?) This is the error code I'm getting.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
GridPathfindingSystem is what I made in the Pathfinding video kzbin.info/www/bejne/l524YWeeq99pgpY But the goal of the modular system is so you can use it with any pathfinding system like the built-in NavMesh kzbin.info/www/bejne/l6WmgJdqpJynfZY
@daltonguthrie3544
@daltonguthrie3544 2 жыл бұрын
@@CodeMonkeyUnity I've looked at everything and all I can't anything that should be giving me this issue. I've even downloaded all the project files from both videos and it is still giving me the same error code. Maybe I'm just being dumb but I have no idea how to remedy this issue. I have all the Unity packages downloaded as well.
@magictimm4090
@magictimm4090 4 жыл бұрын
When I use the pathfinding script I have an error. I copied the code (PlayerMovementMouse, MoveTransformVelocity, MovePositionPathfinding, plus the interfaces) from the project files in my own project. And I copied the grid scripts too. Any help? I opened a complete new project, add your projectfiles and.... same result. NullReferenceException: Object reference not set to an instance of an object MovePositionPathfinding.SetMovePosition (UnityEngine.Vector3 movePosition) (at Assets/Scripts/MovePositionPathfinding.cs:14) PlayerMovementMouse.Update () (at Assets/Scripts/Player/PlayerMovementMouse.cs:13)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Use Debug.Log to figure out exactly what is set to null
@magictimm4090
@magictimm4090 4 жыл бұрын
@@CodeMonkeyUnity First: thanks for your great videos and the support Debug.Log(pathVectorList); is NULL Debug.Log(movePosition); is not NULL (-2.8, -1.7, 0.0) Debug.Log(transform.position); is not NULL (1.8, 0.4, 0.0)
@magictimm4090
@magictimm4090 4 жыл бұрын
@@CodeMonkeyUnityI found the problem. I deleted the GameHandler_Setup script and object
@gamespark3426
@gamespark3426 2 жыл бұрын
when I use GridPathFinding VS cannot find it and said that "Error CS0246 The type or namespace name "gridpathfindingsystem" could not be found"
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
That's not a built-in Unity class, it's the Pathfinding that I built in a previous video kzbin.info/www/bejne/l524YWeeq99pgpY
@gamespark3426
@gamespark3426 2 жыл бұрын
@@CodeMonkeyUnity understood. Thanks bro.
@onetruedom8432
@onetruedom8432 4 жыл бұрын
Are Update() methods called at different intervals? After changing my code to be more modular there seems to be a delay in my players velocity changing to zero when I have no keys pressed. --- Before --- PlayerMovement - Update() - Capture Input - FixedUpdate() - Update RigidBody velocity --- After --- PlayerInputsController - Update() -> Call PlayerMovement.SetVelocity() PlayerMovement(RigidBody) - SetVelocity() -> Sets Parameters for use by FixedUpdate() later - FixedUpdate() -- Update RigidBody velocity Any reason why this feels slightly slower? I feel like this shouldn't be a noticable change.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Update(); gets called on every frame whereas FixedUpdate(); is on a fixed interval which is also when the Physics system runs You can set the velocity on Update(); and it will be applied on the next FixedUpdate(); That code doesn't seem like it would be any slower, is your rigidbody set to interpolate?
@onetruedom8432
@onetruedom8432 4 жыл бұрын
@@CodeMonkeyUnity Yeah my rigidbody is set to interpolate, I'll have to come back and give this another look. Thanks for the reply anyways
What are Interfaces? (C# Basics)
13:54
Code Monkey
Рет қаралды 200 М.
How I added LOTS of weapons to my game!
5:18
Bardent
Рет қаралды 48 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 795 М.
Miracle Doctor Saves Blind Girl ❤️
00:59
Alan Chikin Chow
Рет қаралды 55 МЛН
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
The Worlds Most Powerfull Batteries !
00:48
Woody & Kleiny
Рет қаралды 24 МЛН
2D PATHFINDING - Enemy AI in Unity
23:13
Brackeys
Рет қаралды 800 М.
Finite State Machines in Godot | Godot Starter Kit FSM
9:46
ForlornU
Рет қаралды 18 М.
Flexible LOOT SYSTEM in Unity with Random Drop Rates
13:24
20 Advanced Coding Tips For Big Unity Projects
22:23
Tesseract
Рет қаралды 153 М.
ENEMY AI - Making an RPG in Unity (E10)
9:25
Brackeys
Рет қаралды 532 М.
СҰЛТАН СҮЛЕЙМАНДАР | bayGUYS
24:46
bayGUYS
Рет қаралды 795 М.