Moving Characters in Games - Kinematic Character Controller in Unity

Investigating how players move in games with Unity.
Try out the demo at nickmaltbie.com/OpenKCC
GitHub project at github.com/nicholas-maltbie/O...
OpenKCC Series Playlist - • Open-Source Kinematic ...
How a player moves through a virtual space is not always clear and straightforward. Defining physics objects to interact with each other in a clean and expected manner is important to creating any game. In this video, I describe how to move a kinematic character controller through a 3D space using unity and provide visualizations and examples. The project that this kinematic character controller is a part of is open source and can be found at the GitHub project link in this description. I will be continue making new videos in this series going over more details on how the character controller camera work in Unity.
Chapters:
Intro 0:00
Character Motion Types 0:19
Camera Movement 1:10
Basic Player Movement 1:43
Collision Detection 2:29
Bouncing and Sliding 3:30
Gravity is Always Getting Me Down 4:35
Sticking to the Floor 5:10
Putting It All Together 5:50
Designing and Debugging 6:22
Outro 6:56
Games in the order they Appear
* Celeste
* Overwatch
* Rock of Ages II
* Quake
#gamedev #unity3d #madewithunity

Пікірлер: 62

  • @33KAIRO.
    @33KAIRO. Жыл бұрын

    This is explained in a way that makes it much more understandable, thank you!

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

    Every game dev should watch this video, amazing explanation and demo project. Congratulations!!!!!

  • @SimonTysland
    @SimonTysland2 жыл бұрын

    Dude, you deserve more views. Well presented and good explanation of a topic that is actually hard to wrap your head around!

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    Thanks. I'll be making more videos and keep updating the open-source repo with examples and documentation.

  • @foldupgames
    @foldupgames2 жыл бұрын

    My head hurts just watching the summary!!!! Glad people like you understand and engage with it.

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    Tried to make it accessible to any experience level. Hopefully it was a bit entertaining to watch as well :) If you have any questions about the algorithm I’m happy to explain more as well.

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

    This is amazing. I'm learning a ton by going through your very well-written, well-commented code. This controller fixes a lot of problems I've seen with other controllers. I can't find anything like it. I really appreciate this!

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    I’m happy you like the videos! I’m working on overhauling some of the KCC code to use a state machine design and fully documenting some of the designs of the project in the GitHub repo as well. Feel free to open an issue or leave a comment if you have any suggestions or questions :)

  • @jadonmullinex9389

    @jadonmullinex9389

    Жыл бұрын

    @@NickMaltbie That's awesome! I'd love to see the overhaul! I've been looking at your code a lot and learning how I'd go implementing some of the same practices into my own character controllers. I'm subscribed now, so looking forward to any updates.

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Thanks! I’m currently updating the GitHub repo with some documentation and tests. I’ll be sure to post a new video when I have any updates as well.

  • @felipinhosinoti
    @felipinhosinoti2 жыл бұрын

    Wow, this video its very good. I wasn't prepared for the knowledge I received

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    This is my favorite comment I’m gotten on the video, I’m happy you liked it! I did make this video in a series and the other videos ramp up to this topic, playlist is in the video description. Check out the other videos in the series.

  • @felipinhosinoti

    @felipinhosinoti

    2 жыл бұрын

    ​@@NickMaltbie haha cool! I will watch the playlist for sure, thanks for the recommendation

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    Thanks, I hope you like the videos!

  • @user-mh1qo4xj8s
    @user-mh1qo4xj8s2 жыл бұрын

    This is exactly the kind of topic I’ve been looking for. Thank you so much for making such a concise explanation. I’ve been trying to make my own CharacterController with the limited knowledge I have and this could help immensely.

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    Thanks. I'll keep updating this series with more videos explaining how the KCC works with visual examples. The project is open source, and you can find it here github.com/nicholas-maltbie/OpenKCC (I think I had the wrong link in the description before). CharacterControllers are a bit more complex than I expected as well, it took me a while to get all these concepts and design running smoothly enough for a demo. I'm happy to answer any other questions about how the character controller works or explain parts of the code in the repo if you have any questions.

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

    This is probably the best explanation video of this topic on KZread. I've actually been creating pretty much the same thing on-and-off since last summer, and have learned so much from doing it. Making your own character controller is one of the most powerful things you can do for your future game development.

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Happy you liked the video. Doing something that seems basic like a character controller that is built into lost game engines helps you understand how they work and how they aren’t actually that simple when you ask questions like how does it check if it’s on the ground!

  • @dead2gamer
    @dead2gamer9 ай бұрын

    Hey Nick I came across KCCs in Nvidia's documentation and your series was the best one I've come across to help me understand them even better. Honestly, I'm struggling with understanding wall collision. I keep clipping through the walls. I'd love some help here. Again absolutely lovely series and I love what you're doing

  • @NickMaltbie

    @NickMaltbie

    9 ай бұрын

    Hey, happy you liked the video. Wall clipping caused a lot of issues with my early versions of the OpenKCC as well. Basically at distances under 0.001 units, physics sometimes brakes down in the unity engine. I’m working on a fix for skin width to get around this without having the player float off the ground. If you have any other questions feel free to tag me in a reply or open an issue on the GitHub page.

  • @huseyindogan7404
    @huseyindogan74042 жыл бұрын

    Nice!

  • @NickMaltbie

    @NickMaltbie

    2 жыл бұрын

    Thanks!

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

    superb work

  • @REAVER_Game

    @REAVER_Game

    Жыл бұрын

    running project is absolutely painful though, sadly D:

  • @REAVER_Game

    @REAVER_Game

    Жыл бұрын

    couldnt import the project, ffs this package manager shenanigans

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    What’s the error you’re running into? Someone helped me debug some import errors on GitHub to patch for version 1.0.1 :) I should update the readme to reference that version instead of 1.0.0

  • @REAVER_Game

    @REAVER_Game

    Жыл бұрын

    @@NickMaltbie for example unity cant get your StateMachineUnity package(i fed git url to package manager) (other packages of yours are downloaded correctly)

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Oh, that makes sense. You should be able to download it via git manually with a path like this - github.com/nicholas-maltbie/StateMachineUnity.git#release/v1.1.0 There is also an archive of the package on npmjs if you want to just download and import manually if the auto import isn't working! www.npmjs.com/package/com.nickmaltbie.statemachineunity Let me know if you need any help with it.

  • @matheusreidopedaco
    @matheusreidopedaco2 ай бұрын

    Hi. Could you explain the reason for the bounces? In the simplified KCC, why do we need to limit the iterations of the while loop? In fact, why the loop at all? Thanks in advance!

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

    Could you potentially go more in-depth on collision itself, as in, how one would code that? I don't really learn much from just copying code or reading a finished script, for me it specifically is something I can understand if it's in a format like this video.

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Hey, hope you liked the video so far. Would you want me to include a more in depth explanation of how the code itself works? I would love to explain that but I’m not sure if people want to look at the code instead of the visualizations. I might try including the lines of code that move the character and explain how I made those visualizations of how the character colliding with objects and go into the code that makes it work :)

  • @blinkachu5275

    @blinkachu5275

    Жыл бұрын

    @@NickMaltbie my main issue is that I do understand how the collision itself works, to the point where I can visualize it myself, but the problem then is that I have yet to figure out how to move the character at the same speed over the hit.distance, and then also project the rest of the movement onto the surface normal. Right now I have the distance the character moves basically to be set to hit.distance if there is a collision so obviously it moves slower as it approaches the wall and then it stops (same goes for slopes... but atm I'm just looking to see if I can make it work until the wall) I don't really need the code itself, for me the way I learn best (and I'm sure others are like this) is if the concept itself is explained in depth. Like if someone says to me "f = -kx" for a spring, I have no idea what that means nor how I would implement it. But if someone goes "k is the spring stiffness, x is the length of the spring, or what you could call the hit.distance. Multiply them to get the spring force that allows the spring to compress and decompress" (just an example of a topic that took me way too long to understand). Same goes basically for code. A lot of the time when people do tutorials they either show just "copy my code" or not even that, which is why I really appreciated this video as I do grasp the concept you're conveying, I just have a hard time translating it ^^ Thanks for the reply tho! Appreciate you taking the time.

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Yes, I see what you mean. Seeing code or a finished solution doesn’t help me very much either, it helps to see a scenario and explain what the code is trying to do and how it works instead of just seeing a final result. I want to make a follow up video on how the character controller handles stairs. There is this concept I’ve found online called bounce and slide based movement (similar to quake engine) for moving the character. I’ll make sure to cover these topics in more depth when I discuss the stairs and handling overlapping objects/pushing the character (think like opening a door and it pushes the character out of the way). Nvidia has some great docs about how the KCC from their PhysX library works and I’d recommend checking those out too if you’re interested ( gameworksdocs.nvidia.com/PhysX/4.1/documentation/physxguide/Manual/CharacterControllers.html ). I’m trying to write up more text documentation in addition to the videos but haven’t had as much time for these projects lately. Thanks for the feedback on the videos. I’ll make sure to include these descriptions and discussions in the next video I make about the KCC.

  • @blinkachu5275

    @blinkachu5275

    Жыл бұрын

    @@NickMaltbie Ohh, implementing Quake/Source based movement is what I've wanted to do for quite a wall (can get it to work on a flat plane but once slopes get introduced it gets tricky again), so would love to see your take on it ^^

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    @@blinkachu5275 that does sound like a fun project. I’m trying to make the OpenKCC library more modular so it supports more use cases and can adjust it as needed. My end goal is to write a Celeste, Quake, Breath of the Wild, and Genshin Impact style character controller by configuring the setting differently as examples! Just the code is a bit buggy now and needs some more work before I can move onto those topics. Happy to know people would be interested in that. I need to finish writing up some basic structure code and adding in things like testing and a state machine design to the project before I move into those samples though.

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

    when your character moves forward, is she simply "Teleported" forward? So you just set her location to a new location after doing a capsule trace?

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Yep, but the character teleports at a rate of 60 times per second very small distances so it should look like the character is moving smoothly

  • @chadgtr34
    @chadgtr349 ай бұрын

    if it is a first person shooter game, can this character be shot on the arm and the body will stand still, fall to the back ? will this bullet be counted in collision detection ?

  • @NickMaltbie

    @NickMaltbie

    9 ай бұрын

    You can if you want to but most games objects like projectiles are in a special physics layer so they don’t interact with other physics objects.

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

    This github repo is the most unreadable thing I've ever seen dear god

  • @NickMaltbie

    @NickMaltbie

    Жыл бұрын

    Sorry to hear that, feel free to open an issue on the repo if you have any suggestions or ideas to make it more readable.