Collide And Slide - *Actually Decent* Character Collision From Scratch

84,080
0
Published 2023-07-30
How to make actually decent collision for your custom character controller. Hopefully you find this helpful and people will finally stop saying "jUsT uSe DyNaMiC rIgIdBoDy!!!1!!11!!"

Chapters:
00:00 - Intro
01:09 - Algorithm
05:11 - Implementation

Improved Collision detection and Response (Fauerby Paper):
www.peroxide.dk/papers/collision/collision.pdf

Improving the Numerical Robustness of Sphere Swept Collision Detection (Linahan Paper):
arxiv.org/ftp/arxiv/papers/1211/1211.0059.pdf

Motion graphics made with motioncanvas.io/

Intro music:
Woody Path (Eastward OST)

Music provided by #uppbeat:
uppbeat.io/t/kem/reborn
License code: M8NYNY1BFZVQQIKR

---------------------------------------------------------------------

Main channel: ‪@poke_‬
Twitter: www.twitter.com/poke_bd
Twitch: www.twitch.tv/poke_bd
Support me on Ko-fi: ko-fi.com/poke_bd

#unity #collision

All Comments (21)
  • @cauhxmilloy7670
    It is nice to see push back on the annoying trend of internet replies which promote not trying and just generally being dumb. Making things from scratch, or making your own version of something, is very powerful. It's really at the heart of engineering, understanding, and creative expression. Thank you very much for promoting people to not just accept the status quo. Reinventing wheels isn't bad when available wheels suck. Instant like and subscribe.
  • @Sophed
    This is unreasonably underrated, incredibly high quality content. Keep it up man <3
  • @shadowofcat
    bro came out of literally nowhere and made one of the most helpful and high quality ive seen in a very long time
  • I'm happy to see you found my old paper useful! Not quite sure I follow the reasoning behind normalizing and re-adjusting the length of the projected vector in the sliding part, but this has been discussed in the comment section already ;) Great presentation and great video though!
  • @yuichikita6018
    For Godot users: This is said in the documentation but, if you ever want to do this in Godot (with that I mean don't want to use the built in move_and_slide function), the engine provides the method move_and_collide() that does the collision casting + the movement, and the Vector2/3.slide() function to calculate the reaction movement.
  • @poke_gamedev
    Update 2: Ok so Unity is currently imploding... I was working on refactoring and adding stair detection, but I might take a detour and learn Godot now lol As someone in the comments pointed out, maintaining full velocity on slopes is not very physically accurate, so I thought I should clarify that all the fancy scaling I'm doing is specifically meant for *character movement*, and should be ignored if using this code for a more general physics engine! Again, thanks for watching, and I hope you found this video helpful!
  • @FractalWanderer
    Dude, this is THE most underrated channel I've ever seen. Top notch content, will be using this, and I subscribed
  • @Banaaani
    I have roughly 5 years of pretty much daily experience with Unity and C#, and I still learned a lot in this video. Awesome stuff!
  • @jadephoenix5837
    Arguably one of the most well presented tutorials Ive ever seen. Fantastic job!
  • @kruth6663
    This is easily one of the best videos about movement and collision I've seen on youtube.
  • @gftk5566
    Underrated. I see this is the first video in this channel so, no hopes are gone. Expect to pop off!
  • @rhythmmmmm.
    This video probably would have helped me out tremendously a few years ago. I self taught myself Unity and refused to use anything anyone else made, so I spent probably a good year perfecting the movement in my own game, trying as hard as I could to figure out the stuff you're describing in this video. I eventually did it with a slightly different method, and I don't regret it because it ultimately taught me so much about the way things work, between time, frames, how acceleration, velocity, friction, etc work, but it's good that nobody else will have to go through the hell that I did. The issue you have described around the 10:30 mark ended up with my character getting their head stuck on any negative angle ramp collision, and at a certain point, actually ended up making them able to walk up the ceiling like a spider. I don't remember what I did to fix it, but I'll have to check out the paper on it.
  • @dvzdev
    This is incredible video quality! Needs to be seen by more people, hope you get the attrntion you deserve
  • @Saidriak
    So glad someone answers this question properly, a year or two ago I couldn’t find any help on the matter and came up with my own hacky but functional solutions
  • @lorz9442
    The explanations and production value of this video is off the charts! Awesome video :) thanks
  • @albingrahn5576
    good video! just wanted to point out that normalizing the vector at 4:00 only to multiply it by the dot product at 9:05 is unecessary since it reverses the normalization (it's like if you would multiply a number by 10 and then divide the result by 10, the second operation reverses the effects of the previous one). if you only want that "sliding along the wall" effect you can skip both steps to get the same result cheaper.
  • @jamesclark2663
    I've written many many character controllers over the years and this one is pretty top quality for how simple it is. In fact, it solves an issue I currently have which is that the controller I designed for my player is very fully featured but a bit too heavy-weight to use at scale. However, I needed a character controller that functioned similarly for NPCs. This little function saved me at least a day of tearing out chunks of some of my own controllers to get something that functioned well and was still resonably performance. Great video!
  • First of all, this video slaps, no question. I was struggling for some number of hours creating a controller for exploring a 2.5d top down map with potentially sloping terrain. I found solutions for moving on slopes, but there were always problems addressing steep slopes (among other things). This is the first video I've found that addresses those problems while still using a similar algorithm for moving up slopes. The one gripe I have is I don't like when people say something is the "right way" or "actually good" when it comes to programming, because there are multiple valid ways of doing things, and some people don't always have the time to implement everything from scratch. The Unity character controller addresses these problems and has parameters for slope limit, skin width, etc. It's a perfectly valid way of doing things. I just didnt want to use it in this instance because our game had potentially unique requirements, and I wanted to understand the math myself anyway.
  • @andremarques4063
    Poke Dev, you are amazing. Poke Dev please continue posting videos. Just writing your name so the algorithm can push you up. Damm, this video was amazing. From the editing to the content, it was so nice to watch I was thinking I was watching a Million subscribers youtube channel. Keep it up and you are going to make it far!