Тёмный

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

Code Monkey
Подписаться 538 тыс.
Просмотров 86 тыс.
50% 1

🌍 Go to admix.in/ and Start Earning Revenue in under 24 hours!
✅ Get the Project files and Utilities at unitycodemonke...
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 unitycodemonke...
📝 Get the Code Monkey Utilities at unitycodemonke...
#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: unitycodemonke...
- Twitter: / unitycodemonkey
- Facebook: / unitycodemonkey

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 250   
@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 4 года назад
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.
@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.
@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 😊😊
@TripleCreeper3
@TripleCreeper3 3 года назад
i bought 2 courses and saw around 20 tutorials to find finally one that is oriented to changing movement, weapons, etc... Much thanks!!!
@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 3 года назад
Not going to lie, I love you for introducing me to interfaces. Thank you SO very much for your invaluable content!
@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)
@FICHEKK
@FICHEKK 4 года назад
Amazing and very helpful video! Please do more of these "good-design" and "architecture" videos!
@janmarcbaniqued7612
@janmarcbaniqued7612 4 года назад
This is amazing!!! I didn't know we can use interfaces like that. This changes so so much thank you!
@PatagonianDuck
@PatagonianDuck 4 года назад
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
@paulblart7378
@paulblart7378 3 года назад
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!
@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!
@PatagonianDuck
@PatagonianDuck 4 года назад
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 3 года назад
@@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...
@eierschaedl
@eierschaedl Год назад
i love the sound of your keyboard. so satisfying.
@LoopyWolf
@LoopyWolf 3 месяца назад
Presented very logically
@oldcat1790
@oldcat1790 4 года назад
Interfaces video sounds interesting.
@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
@supapaw
@supapaw 8 месяцев назад
6:52 actually it has two purposes: to move the rigidbody AND play the animation :)
@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.
@LoopyWolf
@LoopyWolf 4 месяца назад
All this code, and a great tutorial.. Support!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 месяца назад
Thanks for the super thanks! I'm glad you found the video helpful!
@LoopyWolf
@LoopyWolf 4 месяца назад
@@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 4 месяца назад
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.
@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?
@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!
@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...
@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.
@keetee-ei3er
@keetee-ei3er Год назад
float moveX = 0f; float moveY = 0f; if (Input.GetKey(KeyCode.W)) moveY = +1f; if (Input.GetKey(KeyCode.S)) moveY = -1f; if (Input.GetKey(KeyCode.A)) moveX = -1f; if (Input.GetKey(KeyCode.D)) moveX = +1f; So does moveX and moveY automatically returns back to zero after either one W,S,A,D key is released (GetKey=false)? Thanks, appreciate this channel and everyone involved!
@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?
@kerduslegend2644
@kerduslegend2644 4 месяца назад
this is a great tutorial. although i have a several question, for example "should you reparate animator logic with a movement logic?"
@CodeMonkeyUnity
@CodeMonkeyUnity 3 месяца назад
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.
@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
@extremeliving592
@extremeliving592 Год назад
You sir, are a genius...
@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!
@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 4 года назад
@@CodeMonkeyUnity This is the best argument read yet for using an Interface vs. Abstract class. Good job.
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Eyx3EfqqfMw.html When the enemies get spawned they are static, essentially they have their logic and move components disabled while the spawn animation finishes.
@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
@kruth6663
@kruth6663 3 года назад
This is what I'm looking for. Thanks!
@dodo5045
@dodo5045 Год назад
why cant u have 2 scripts using the same interface with 1 disabled, u have to remove the other component completely?
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-11c9rWRotJ8.html
@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
@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
@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/
@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.
@mohameddabbour6961
@mohameddabbour6961 4 года назад
Yes! please make video about interfaces
@digitalfortress1208
@digitalfortress1208 3 года назад
Dude you are awesome. This is good stuff.
@kken8766
@kken8766 4 года назад
Please make a video about interface!!!~~~
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
A function signature is the definition of the return type and the parameters. void TestFunction(int i); The signature for this function is it returns void and takes an int parameter. Interfaces being a contract means you HAVE to implement those functions, if you don't you get a compiler error.
@kken8766
@kken8766 4 года назад
@@CodeMonkeyUnity
@benjaminsnow5095
@benjaminsnow5095 4 года назад
Absolute mad lad! You are truly epic!
@mohokhachai
@mohokhachai 11 месяцев назад
Professional tutorial
@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!
@theashbot4097
@theashbot4097 Год назад
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 Год назад
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
@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.
@kylemedina5112
@kylemedina5112 2 года назад
Notes: 11:16 Using Interface script for the ability to switch between scripts(that inherit from the Interface class)
@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.
@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?
@MB-eq9ew
@MB-eq9ew 3 года назад
Using get component in update , is same with getting in start but way more optimization problem right ?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
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
@zekiozdemir420
@zekiozdemir420 3 года назад
Thanks for making these videos
@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
@kamalamy
@kamalamy 8 месяцев назад
when you do an if statement "Vector3 moveDir = Vector3.Distance(movePosition, transform.position) < 1f)" why not just use a ternary operator like "Vector3 moveDir = (Vector3.Distance(movePosition, transform.position) < 1f) ? Vector3.zero : (movePosition - transform.position).normalized;"?
@CodeMonkeyUnity
@CodeMonkeyUnity 8 месяцев назад
No specific reason, it's just personal preference
@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
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-0jTPKz3ga4w.html
@Michal005
@Michal005 4 года назад
How to change this scripts by code???
@nikolasxyinidis7514
@nikolasxyinidis7514 4 года назад
Thank you soooo much this is very helpful
@umairmalik6480
@umairmalik6480 4 года назад
Please make a video on interface also
@gfulpakwuli3799
@gfulpakwuli3799 3 года назад
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 3 года назад
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.
@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.
@LekoKeller
@LekoKeller 2 года назад
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 2 года назад
Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
@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.
@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.
@FyresGames
@FyresGames 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?
@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
@notrue4u
@notrue4u 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.
@daltonguthrie3544
@daltonguthrie3544 3 года назад
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 3 года назад
GridPathfindingSystem is what I made in the Pathfinding video ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-alU04hvz6L4.html But the goal of the modular system is so you can use it with any pathfinding system like the built-in NavMesh ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-atCOd4o7tG4.html
@daltonguthrie3544
@daltonguthrie3544 3 года назад
@@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.
@andrewshandle
@andrewshandle 4 года назад
This is great.
@thedevquest7676
@thedevquest7676 4 года назад
PLEASE! make a video on interfaces! I'm really struggling to find a good source to learn good coding principles. It's come to my attention that all if not almost all unity novice tutorials I've done over the last 3 weeks and about 70 + hours of my time have been teaching my very BAD code practices. ie. not implementing SOLID principles, HUGE player classes and no composition or interfaces. I've looked high and low for a good 2D top down or 2d platformer tutorial that implements all these good practices while teaching C#. I can't seem to find it anywhere so If you could cover them even separately that would be amazing!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
I just published a video on interfaces today! ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-MZOrGXk4XFI.html
@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 ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-alU04hvz6L4.html
@gamespark3426
@gamespark3426 2 года назад
@@CodeMonkeyUnity understood. Thanks bro.
@john2377
@john2377 3 года назад
Is it good if we use the GetComponent right inside the Update method and also to declare variables? Doesn't it affect the performance of the game?
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Yes I did that only for demo purposes so I could hot swap the components in runtime, in your own games you should definitely cache the values and not do GetComponent on every Update
@andylockhart257
@andylockhart257 4 года назад
Yes please on Interfaces!!
@dannykay4649
@dannykay4649 4 года назад
Please do a dedicated video on interfaces!
@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?
@Semaj0z
@Semaj0z 4 года назад
Why don't u use getaxis for the player wasd movement
@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.
@SanderVerveer
@SanderVerveer 3 месяца назад
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 3 месяца назад
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
@AdidasDoge
@AdidasDoge 2 года назад
The move postiion direct usually overshots the target position, how can I solve this?
@CodeMonkeyUnity
@CodeMonkeyUnity 2 года назад
You can check the current and the next position, do a distance check to the target, if the next position is further away then the current, just set the next position to be the target position.
@AdidasDoge
@AdidasDoge 2 года назад
@@CodeMonkeyUnity Sorry, I am a beginner, could you please provide an example of the code?
@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.
@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
@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.
@joaohudsonlacerdaoliveira5253
@joaohudsonlacerdaoliveira5253 3 года назад
Warning: GetComponent in Update method contains this additional overhead, use: private ExampleType value; void Start(){ value = GetComponent(); } void Update(){ //use value... }
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
Yes, the method in the video was made to support hot-swapping for demonstration purposes. If you use the final modular character controller in a finished game you should definitely cache the component.
@lordzombieboy
@lordzombieboy 3 месяца назад
Tutorial start: 5:40
@unofficialSummer
@unofficialSummer 3 года назад
That Admix Idea looks promising, I would like to hear anyone's experience with that.
@waltuh08
@waltuh08 4 года назад
you are the best thank you
@SebyGamerZROZ
@SebyGamerZROZ 4 года назад
Nice work ! ✓
@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
@shanjohnkj6851
@shanjohnkj6851 4 года назад
Please explain how moveposition - transom. Position works its been long time searching for crrt answers
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
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 4 года назад
@@CodeMonkeyUnity brooo thankyouuu
@Cultofcosmossubscriber
@Cultofcosmossubscriber 2 года назад
Actual video starts at 0:00
@GamernetsLP
@GamernetsLP 2 года назад
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 2 года назад
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.
@ronnid8837
@ronnid8837 4 года назад
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 4 года назад
I covered a basic state machine here ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-db0KWYaWfeM.html 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 4 года назад
@@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) ...
@chrolloace2032
@chrolloace2032 3 года назад
would it not be better to make one script named movement and have a enum with different movement types such as public enum MovementTypes { Transform , RigidBody } public Enum MovementHandlers { WASD , MousePosition } and then have variables and change them accordingly with a custom editor script depending on the enum values
@CodeMonkeyUnity
@CodeMonkeyUnity 3 года назад
If you go with that approach then you end up with a massive 1000 line script. Better to keep things separate and organized
@chrolloace2032
@chrolloace2032 3 года назад
@@CodeMonkeyUnity Yes! you're right thank you. I am currently applying this modular system to make a weapon system. Thanks for your reply , your videos are amazing!
@walney2008
@walney2008 4 года назад
ola nao consigo importar error Failed importing package C:/Users/Walney.DESKTOP-NACG4H2/Desktop/Unity/Monkey/ModularCharacter.unitypackage UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
What Unity version are you using?
@walney2008
@walney2008 4 года назад
2019.3.5.f1 , tnhks videos, study integrate Unity x MySQL, Get,Post,Delete
@walney2008
@walney2008 4 года назад
you speak use public static Networking.UnityWebRequest Post(string uri, string postData); ? Unity x MySQL ?
@philiphanhurst2655
@philiphanhurst2655 4 года назад
It's probably not the best idea to use GetComponent() in Update, since from what I've heard it can be pretty heavy.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 года назад
Yup true, I only did it that way to showcase hotswapping the modules in the demo. In a final game you would choose what modules you wanted and do GetComponent on Awake.
@LoopyWolf
@LoopyWolf 3 месяца назад
Thanks
@CodeMonkeyUnity
@CodeMonkeyUnity 2 месяца назад
Thanks for the super thanks! I'm glad you found the video helpful!
Далее
What are Interfaces? (C# Basics)
13:54
Просмотров 207 тыс.
The biggest lie in video games
15:18
Просмотров 1,8 млн
Fake watermelon by Secret Vlog
00:16
Просмотров 6 млн
The Most Impressive Scratch Projects
11:00
Просмотров 4,9 млн
I Made the Same Game in 8 Engines
12:34
Просмотров 4 млн
How I made an Excellent Platformer
8:25
Просмотров 275 тыс.
I Optimised My Game Engine Up To 12000 FPS
11:58
Просмотров 657 тыс.
Unity's NEW input system in 13 minutes
13:02
Просмотров 18 тыс.
How do non-euclidean games work? | Bitwise
14:19
Просмотров 2,4 млн
What are Events? (C# Basics)
15:05
Просмотров 389 тыс.
Fake watermelon by Secret Vlog
00:16
Просмотров 6 млн