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

🌍 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

Пікірлер: 243

  • @CodeMonkeyUnity
    @CodeMonkeyUnity4 жыл бұрын

    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
    @Norbingel4 жыл бұрын

    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
    @mcgeufer4 жыл бұрын

    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.

  • @TripleCreeper3
    @TripleCreeper32 жыл бұрын

    i bought 2 courses and saw around 20 tutorials to find finally one that is oriented to changing movement, weapons, etc... Much thanks!!!

  • @raghulponnusamy9034
    @raghulponnusamy90344 жыл бұрын

    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.

  • @mehmedcavas3069
    @mehmedcavas30694 жыл бұрын

    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
    @janmarcbaniqued76123 жыл бұрын

    This is amazing!!! I didn't know we can use interfaces like that. This changes so so much thank you!

  • @oyaguni961
    @oyaguni9612 жыл бұрын

    Not going to lie, I love you for introducing me to interfaces. Thank you SO very much for your invaluable content!

  • @FICHEKK
    @FICHEKK4 жыл бұрын

    Amazing and very helpful video! Please do more of these "good-design" and "architecture" videos!

  • @paulblart7378
    @paulblart73782 жыл бұрын

    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!

  • @tiagodarkpeasant
    @tiagodarkpeasant4 жыл бұрын

    finally the part i wanted to learn, making simple scripts is easy, using all of them in the same object not so much

  • @eierschaedl
    @eierschaedl Жыл бұрын

    i love the sound of your keyboard. so satisfying.

  • @benjaminsnow5095
    @benjaminsnow50954 жыл бұрын

    Absolute mad lad! You are truly epic!

  • @tigransahakyan2840
    @tigransahakyan28404 жыл бұрын

    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
    @danielvillalba44573 жыл бұрын

    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.

  • @kruth6663
    @kruth66633 жыл бұрын

    This is what I'm looking for. Thanks!

  • @justinwhite2725
    @justinwhite27254 жыл бұрын

    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.

  • @nerdact5920
    @nerdact59203 жыл бұрын

    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
    @digitalfortress12083 жыл бұрын

    Dude you are awesome. This is good stuff.

  • @user-hz4tc2pf3x
    @user-hz4tc2pf3x4 жыл бұрын

    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)

  • @zekiozdemir420
    @zekiozdemir4203 жыл бұрын

    Thanks for making these videos

  • @extremeliving592
    @extremeliving592 Жыл бұрын

    You sir, are a genius...

  • @nikolasxyinidis7514
    @nikolasxyinidis75143 жыл бұрын

    Thank you soooo much this is very helpful

  • @Moon-cr4mu
    @Moon-cr4mu Жыл бұрын

    this is so useful, thanks!!

  • @smallg9109
    @smallg91094 жыл бұрын

    thanks, i didn't know about interface scripts :)

  • @mohameddabbour6961
    @mohameddabbour69614 жыл бұрын

    Yes! please make video about interfaces

  • @arcday4281
    @arcday42814 жыл бұрын

    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...

  • @oldcat1790
    @oldcat17904 жыл бұрын

    Interfaces video sounds interesting.

  • @MaGiStReall
    @MaGiStReall4 жыл бұрын

    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!

  • @PatagonianDuck
    @PatagonianDuck3 жыл бұрын

    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

  • @LoopyWolf
    @LoopyWolf24 күн бұрын

    All this code, and a great tutorial.. Support!

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    24 күн бұрын

    Thanks for the super thanks! I'm glad you found the video helpful!

  • @LoopyWolf

    @LoopyWolf

    23 күн бұрын

    @@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

    23 күн бұрын

    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.

  • @personanongrata4419
    @personanongrata44194 жыл бұрын

    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!

  • @mehmedcavas3069
    @mehmedcavas30694 жыл бұрын

    can you also show us how you combined it with your animation script? a simple one with walk, idle and attack would be enough

  • @SebyGamerZROZ
    @SebyGamerZROZ4 жыл бұрын

    Nice work ! ✓

  • @andrewshandle
    @andrewshandle4 жыл бұрын

    This is great.

  • @PatagonianDuck
    @PatagonianDuck3 жыл бұрын

    Add This line if (Vector3.Distance(movePosition, transform.position) 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

    2 жыл бұрын

    where to add this code

  • @PatagonianDuck

    @PatagonianDuck

    2 жыл бұрын

    @@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...

  • @KalponicGames
    @KalponicGames3 жыл бұрын

    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?

  • @waltuh08
    @waltuh084 жыл бұрын

    you are the best thank you

  • @Fyres11
    @Fyres112 жыл бұрын

    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?

  • @mohokhachai
    @mohokhachai8 ай бұрын

    Professional tutorial

  • @ghiancarlostan8730
    @ghiancarlostan87302 жыл бұрын

    is this a good way to create a weapon system? like i should create different scripts per unique weapons based on their attack patterns?

  • @andylockhart257
    @andylockhart2574 жыл бұрын

    Yes please on Interfaces!!

  • @dannykay4649
    @dannykay46494 жыл бұрын

    Please do a dedicated video on interfaces!

  • @techbytefrontier
    @techbytefrontier4 жыл бұрын

    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 kzread.info/dash/bejne/Y2WXm9SQgtLaeps.html

  • @MrAmix2
    @MrAmix24 жыл бұрын

    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 kzread.info/dash/bejne/d62slaefodTMfdo.html When the enemies get spawned they are static, essentially they have their logic and move components disabled while the spawn animation finishes.

  • @gfulpakwuli3799
    @gfulpakwuli37992 жыл бұрын

    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.

  • @ericf.2267
    @ericf.22674 жыл бұрын

    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!

  • @filipgawlik3259
    @filipgawlik32594 жыл бұрын

    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

  • @terry-
    @terry-3 ай бұрын

    Great!

  • @supergalaxysam
    @supergalaxysam3 жыл бұрын

    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 kzread.info/dash/bejne/Yp6Isq2zY8rHZNo.html

  • @utkugokalp3179
    @utkugokalp31794 жыл бұрын

    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.

  • @umairmalik6480
    @umairmalik64804 жыл бұрын

    Please make a video on interface also

  • @MatthewChowns
    @MatthewChowns4 жыл бұрын

    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.

  • @Palutena618
    @Palutena6184 жыл бұрын

    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.

  • @victrolaface
    @victrolaface4 жыл бұрын

    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.

  • @kerduslegend2644
    @kerduslegend26445 күн бұрын

    this is a great tutorial. although i have a several question, for example "should you reparate animator logic with a movement logic?"

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 күн бұрын

    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.

  • @magecode9585
    @magecode95854 жыл бұрын

    very very cool

  • @MalikenGD
    @MalikenGD4 жыл бұрын

    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.

  • @cbr9731
    @cbr97313 жыл бұрын

    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.

  • @magictimm4090
    @magictimm40903 жыл бұрын

    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.

  • @washynator
    @washynator4 жыл бұрын

    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

    3 жыл бұрын

    @@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/

  • @keelanbowker-obrien2222
    @keelanbowker-obrien22224 жыл бұрын

    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

  • @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

  • @danielcorzo7498
    @danielcorzo74983 жыл бұрын

    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.

  • @ronnid8837
    @ronnid88373 жыл бұрын

    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 kzread.info/dash/bejne/lpZkrbmSkbrMlbA.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

    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) ...

  • @MB-eq9ew
    @MB-eq9ew2 жыл бұрын

    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

  • @supapaw
    @supapaw4 ай бұрын

    6:52 actually it has two purposes: to move the rigidbody AND play the animation :)

  • @MrREALball
    @MrREALball4 жыл бұрын

    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.

  • @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!

  • @thedevquest7676
    @thedevquest76764 жыл бұрын

    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! kzread.info/dash/bejne/f46D1KmRm5e-dqw.html

  • @Semaj0z
    @Semaj0z4 жыл бұрын

    Why don't u use getaxis for the player wasd movement

  • @abuUthmani
    @abuUthmani2 жыл бұрын

    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.

  • @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.

  • @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!

  • @Michal005
    @Michal0054 жыл бұрын

    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.

  • @quinclarke2331
    @quinclarke23312 жыл бұрын

    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

  • @unofficialSummer
    @unofficialSummer3 жыл бұрын

    That Admix Idea looks promising, I would like to hear anyone's experience with that.

  • @lucasgiffuni6267
    @lucasgiffuni62674 жыл бұрын

    Hi, can you do a tutorial of melee attack system with the sword?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    4 жыл бұрын

    Yeah I covered it here kzread.info/dash/bejne/c4yfw9OQY6iff6w.html

  • @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?

  • @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.

  • @theashbot4097
    @theashbot409710 ай бұрын

    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

    10 ай бұрын

    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

  • @pabloandresherreracantilla9177
    @pabloandresherreracantilla91774 жыл бұрын

    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?

  • @FergoniusYeet
    @FergoniusYeet3 жыл бұрын

    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.

  • @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

  • @dodo5045
    @dodo5045 Жыл бұрын

    why cant u have 2 scripts using the same interface with 1 disabled, u have to remove the other component completely?

  • @tonyclx
    @tonyclx3 жыл бұрын

    ​ @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
    @shanjohnkj68513 жыл бұрын

    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

  • @kylemedina5112
    @kylemedina51122 жыл бұрын

    Notes: 11:16 Using Interface script for the ability to switch between scripts(that inherit from the Interface class)

  • @johngalt200
    @johngalt2002 жыл бұрын

    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

  • @kken8766
    @kken87664 жыл бұрын

    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

  • @onetruedom8432
    @onetruedom84323 жыл бұрын

    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

    3 жыл бұрын

    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

    3 жыл бұрын

    @@CodeMonkeyUnity Yeah my rigidbody is set to interpolate, I'll have to come back and give this another look. Thanks for the reply anyways

  • @kiss_fish
    @kiss_fish3 жыл бұрын

    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

  • @danielcorzo7498
    @danielcorzo74983 жыл бұрын

    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

  • @philiphanhurst2655
    @philiphanhurst26553 жыл бұрын

    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

    3 жыл бұрын

    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.

  • @akashverma4280
    @akashverma42803 жыл бұрын

    I wanted to learn about interfaces and this video cleared some doubts about interfaces. Time to implement interfaces in my project! Thanks for the video. Also, can you do a video on how an animation system should be built? Cuz I haven't found any resources dedicated to building a modular animation system. Right now, my Animators and AnimationSystemHanndler script have started to become a mess and I think that later on It'd be hard to add features if I wanted to. Thanks again for such a nice video!!

  • @akashverma4280

    @akashverma4280

    3 жыл бұрын

    Also, I heard that Unity is going public! Whether it is a good thing or a bad?

  • @CodeMonkeyUnity

    @CodeMonkeyUnity

    3 жыл бұрын

    I covered how my animation system works here kzread.info/dash/bejne/Y2WXm9SQgtLaeps.html Its all based on dynamically modifying meshes in runtime

  • @byeileft894
    @byeileft8944 жыл бұрын

    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

  • @tiagodarkpeasant
    @tiagodarkpeasant4 жыл бұрын

    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.

  • @Michal005
    @Michal0054 жыл бұрын

    How to change this scripts by code???

  • @kushovu
    @kushovu4 жыл бұрын

    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: kzread.info/dash/bejne/Y2WXm9SQgtLaeps.html

  • @kushovu

    @kushovu

    4 жыл бұрын

    @@CodeMonkeyUnity got this haha thx for all!

  • @adeled8833
    @adeled88332 жыл бұрын

    It didnt go through the wall, my player rotated when touched walls like crazy for some reason with the first (rb) method