Making Custom Car Physics in Unity (for Very Very Valet)

Sdílet
Vložit
  • čas přidán 19. 06. 2024
  • A detailed look at how we made our custom raycast-based car physics in Unity for our game Very Very Valet - available for Nintendo Switch, PS5, and Steam.
    BUY NOW!! toyful.games/vvv-buy
    ~ More from Toyful Games ~
    * Physics Based Character Controller in Unity: • Making A Physics Based...
    * Instant "Game Feel" Tutorial: • Instant "Game Feel" Tu...
    * The Toyful Blog with even more developer deep dives - toyful.games/blog
    * Get Very Very Valet now - toyful.games/vvv-buy
    * Download the FREE demo on Nintendo Switch today - toyful.games/vvv-di
    Video sections:
    0:00 - Intro
    0:28 - Car Physics Overview
    2:43 - 3 Forces per Tire
    4:36 - Force #1: Suspension
    12:26 - Force #2: Steering
    18:40 - Force #3: Acceleration/Braking
    21:59 - Outro
    #VeryVeryValet #NintendoSwitch #MadeWithUnity #GameDev #IndieDev #tutorial #tutorials #howto #PS5 #steam #epicgamesstore #Windows #Mac #PC #CouchCoop #Multiplayer
  • Hry

Komentáře • 386

  • @kalkatos
    @kalkatos Před rokem +174

    If we had an award for best car physics tutorial on CZcams, this one would be - hands down - the uncontested winner!

  • @f11bot
    @f11bot Před rokem +229

    How doesn’t this have more than a million views, seems something out of a popular TV Series, it’s so refined and easy to understand!!

    • @Colonies_Dev
      @Colonies_Dev Před rokem +9

      this is the only video i CANT understand, it seems most of the setup code is missing and it immediately throws extremely fking vague keywords like tiretransform and vague references to rigidbodies that WERENT visibly declared. i have to throw this video out of my mind and move on to a different video on the same topic. its really fucking irritating.

    • @trashcaster
      @trashcaster Před rokem +11

      @@Colonies_Dev What you can do to get this to a more useful state for yourself, put each of these into their own functions, and have all undefined variables be parameters in the functions.
      In the car's controller script, in FixedUpdate, iterate over an array of Transforms (or components called Wheel that have a transform defined and publicly "gettable") you define as the various wheels.
      With each wheel in your foreach loop, you ray cast from the transform it has, along the transform's "down" direction (-transform.up), with a maximum distance of springMaxLength + wheelRadius (you define these in each wheel, but note that the max length of the spring isn't going to tell you the current length, the hit will. Current spring length is equal to the raycast hit's distance minus wheel radius). The success of this Raycast is "rayDidHit".
      I recommend using the wheel component purely as a way to define multiple wheels and their transforms and spring/radius data, possibly to adjust rendering stuff for the wheel. Control the vehicle entirely from a Vehicle Controller script using the loop system, to reduce the number of monobehaviour components used for performance.
      Arguably, you could make wheels not be components, but just a struct that has the values and transforms defined, so it is used as references only, and can be entirely modified in the editor on a single object.

    • @CosimoDavideViggiano
      @CosimoDavideViggiano Před rokem +2

      @@trashcaster I understand the irritating, I also tried to get this work but I only can get work the Y-axis forces (suspension) when I try to add the accelerate/braking force, the car move in a way that is unexpected. So, how all this force are added to the Rigidbody, does order matter? Why not show the entire code? The theory is fascnitang but...need to see it in practice

    • @modjok127
      @modjok127 Před rokem

      @@trashcaster i actually see a problem with this approach, when the wheels get contact, let say after a jump, does it not "suck" the car to their contact point ?

    • @tiernanmccarthy
      @tiernanmccarthy Před rokem +1

      @@Colonies_Dev I hope you found it useful in the end. But if you didn't I would say this is more of a lecture for working something out yourself than a tutorial. It took me a while to construct something out of it, but I have drivable vehicles in a smaller project at work from it. This was a crash course on how to approach the problem, and now the car rig is very much my own.

  • @Why485
    @Why485 Před rokem +44

    This is now the definitive "car physics" gamedev video I will pass around whenever somebody asks about it. The presentation is excellent and the info is great.

  • @_ahmedshalaby
    @_ahmedshalaby Před rokem +59

    I cant emphasis enough how i love this type of videos, I really hope you continue give us more tutorial and tips and tricks along the way, great job.

  • @neipo
    @neipo Před rokem +1

    Such a good series thank you for making these

  • @lucaswk
    @lucaswk Před rokem

    These videos are simply amazing. I'm hyped when I see some uploaded. Thank you so much.

  • @williamchurch8401
    @williamchurch8401 Před rokem +1

    This is incredible! Thank you so much for sharing this ingenious car system!

  • @torryjaja
    @torryjaja Před rokem +1

    this is absolutely fantastic, thank you so much for making this

  • @f1van405
    @f1van405 Před rokem

    Great job! Thank you very much for your tutorials!

  • @tageueland
    @tageueland Před rokem +1

    This is exactly what I was looking for! Very easy to understand and implement.

  • @chienbanane3168
    @chienbanane3168 Před rokem +1

    I didn't expect a tutorial to look this polished! Very informative as well!

  • @andrewalexart
    @andrewalexart Před rokem

    Very satisfying and useful video tutorial! Great job!

  • @QuadeZaban
    @QuadeZaban Před rokem +1

    You guys are crushing it! These videos have been extremely useful. Thanks for the resources, and thanks for the great game too!

  • @juanloutech2864
    @juanloutech2864 Před rokem

    Perfectly explained basic car physics. Great job, amazing video!

  • @reihanmohamed6718
    @reihanmohamed6718 Před rokem

    The quality of the video is so good. I have been watching many videos about car physics in games and this is one has given the most explanation in a very good presentation. Thank you so much. Have already subscribed.

  • @guadog
    @guadog Před rokem +1

    Thank you so much for breaking it down how it works in such an easy to understand way! This really helped me with a game I'm making, so thank you so much!

  • @ririgamesofficial
    @ririgamesofficial Před rokem +1

    This is so incredibly well done. Been banging my head for the passed couple of weeks to try to understand how car physics work and this method is the one that makes the most sense to me.

  • @blinkachu5275
    @blinkachu5275 Před rokem +1

    Thank you so much for this, I always struggled to understand the "side forces" but your simple explanation made them a lot easier to understand

  • @ravendave24
    @ravendave24 Před rokem

    thank you so much for this in depth explanation! i love these kinds of videos!

  • @jojo.s
    @jojo.s Před rokem

    I was trying to understand the steering part on my own, and this explanation made it so simple and easy to understand. Thank you so much for sharing this knowledge!

  • @njdarda
    @njdarda Před 7 měsíci

    i think you struck a perfect balance between realism and and simplicity here. amazing job and great presentation too!

  • @bismarckyjag
    @bismarckyjag Před rokem

    Thank you very much for sharing your knowledge!

  • @tokyowarfare6729
    @tokyowarfare6729 Před rokem

    Insante quality tutorial, the content, the visuals everthing is over the top

  • @MineXplayPL
    @MineXplayPL Před rokem

    Awesome explanation, looked so compilcated and now it's so simple. Definitely buying the game also as a way to say thank you!

  • @luisfidalgo9128
    @luisfidalgo9128 Před 5 měsíci +3

    This is content i would pay for! Understanding the physics and how everything works before any line of code is the best way to learn! Amazing video and thank you for taking the time to make it, with all the in depth physics explanation!

  • @tropochito
    @tropochito Před 10 měsíci

    GOD, What AMAZING TUTORIAL!

  • @sethsandwich
    @sethsandwich Před 4 měsíci

    This was an incredibly good tutorial. Thanks so much for the effort that went into this 🙂

  • @OddStare
    @OddStare Před 6 měsíci

    I love the simplicity of it, thanks for sharing this with such quality ! Less rigidbodies is always a win in my book

  • @boulder_dude
    @boulder_dude Před rokem +18

    The way you broke down the physics with visuals and graphs made it easy to understand and implement. Extremely performant in comparison to calculating a Rigidbody for each of the objects. Thanks for sharing this concept, cheers!

  • @drewbluewasabi
    @drewbluewasabi Před rokem

    Legendary video. Legit would not have been able to make a polished vehicle system if it weren't for this video and the great visualizations!

  • @LuRybz
    @LuRybz Před rokem +1

    Knowledge and learning is gift that gives joy.
    Content like this is priceless, it turns my life more enjoyable.
    Thank your for sharing!

  • @gregoryhause00
    @gregoryhause00 Před rokem

    Thank you for sharing this with us! 😁 I'm sure it wil be very helpful for many people

  • @reversible8740
    @reversible8740 Před rokem +6

    Loving these videos. Really nice rigid body controls in unity with explanations are hard to come by. Definitely gonna check out the game.

  • @oldshamen
    @oldshamen Před rokem +23

    How you illustrate and explain each part is really amazing. Top quality tutorial that focuses on explaining the why instead of just spending 30 mins typing code. Love it.

  • @Bloodlinedev
    @Bloodlinedev Před rokem +2

    This is absolute gold. I have wrangled with the buildin car for years now, this video makes it look super easy. Will def use this the next time I need vehicles. Thank you so much.

  • @mrskomps
    @mrskomps Před 7 měsíci

    This helps a phenomenal amount, thank you so much for this!

  • @Vsev0l0d
    @Vsev0l0d Před rokem

    Great stuff! Keep going, its very interesting game mechanic.

  • @ElvishJumpSuit
    @ElvishJumpSuit Před rokem

    I really enjoyed your way of breaking down the fun of your game into simple physics. Never seen a more obvious link to the modern relevance of the subject. I hope that my students will be inspired by your engaging delivery. There is a parallel universe where you are a cracking physics teacher!!!

  • @haikunHuanghk
    @haikunHuanghk Před rokem

    finally, some one explained clear on Damping. :P Good job Toyful Games!

  • @ragerungames
    @ragerungames Před rokem

    Thanks!! Finally i achieved the suspension part using hooks law and your guide. Time
    To make traction better now!!

  • @bovineox1111
    @bovineox1111 Před měsícem

    This is a great solution. Love it.

  • @psychedeliccoffee2737
    @psychedeliccoffee2737 Před 5 měsíci +1

    Please make more of these dev-style videos. They are amazing

  • @redsunpro
    @redsunpro Před rokem +1

    This video is great. Totally took me out of my dev rut. I was struggling with unity's built in vehicle dynamics. Gonna code this in 🙂

  • @dziemon
    @dziemon Před rokem +1

    This is a fully professional course video for free. Thank you so much! Good to see you still active here in the comments. I am tinkering with this concept on my own and found some success. Hope Toyful Games are still operating and you are cooking something new!

  • @ChillGuyYoutube
    @ChillGuyYoutube Před rokem +1

    this is an amazing tutorial hands down, there should be more game developers posting devlog-like videos on how their game works, it's so helpful to small developers!

  • @DovyBL
    @DovyBL Před rokem +1

    Best car physics video ever! ♥

  • @lionn00b
    @lionn00b Před 11 měsíci

    awesome video! really helpful, thank you.

  • @Glados44
    @Glados44 Před 9 měsíci

    I buyed your game. 1000% Sure this is the best game. And the best video to explain how you made the car physics. You deserve everyone talking about this cause you are the only one out there making a well explained controller for cars. Thank you for this!

  • @devin18101
    @devin18101 Před rokem +4

    YOU ARE MY SAVIOR, lmao thank you so much! This game actually looks pretty fun and I am going to check it out. I have been looking for a video like this for YEARS, and finally the youtube algorithm has connected us! I really do appreciate the depth and simplicity as well as the visuals to make it as easy as possible to really understand what actually goes on behind the scenes in a conceptual way.

  • @geri4367
    @geri4367 Před rokem +1

    This is so sooo soooooo good. Thank you so much

  • @rahulcorleone4222
    @rahulcorleone4222 Před rokem

    Great job with explaining, I did not found better than this with example code on the internet. We can find more details about power curves, gears and transmission, air drag, rolling friction, ... , etc for a more accurate simulation on internet, but the foundation is here.

  • @YouCodeThings
    @YouCodeThings Před rokem

    Brilliant breakdown!

  • @piyushguptaji402
    @piyushguptaji402 Před rokem +3

    this was the best explaination i heard.... i love you man. unity's default wheel collider is sluggish, so i went for a raycast approach, i did achiece suspension, but had no idea of friction. i really appreciate you taking time to make all this illustration and explaining us

  • @victorbarreto1067
    @victorbarreto1067 Před rokem +2

    This is very nice, really! I have been developing a similar game, but there is still a long way to go, but I'm learning a lot while developing. Now I'm in the process of developing the car physics. I was inspired by a very old game from miniclip called "Park a Lot".

  • @marekhusenica3400
    @marekhusenica3400 Před rokem

    This video is too good to exist :D Helped a ton

  • @user-ly3fs9jl2p
    @user-ly3fs9jl2p Před rokem

    so much effort for tutorial. great work

  • @Brovioli
    @Brovioli Před rokem +15

    Please make more programming videos. Your explanations and breakdown of the topic was S Tier. So many other youtubers still leave me with many questions. But I was able to follow along and understand this the whole way through.

  • @PartTimeMonkey
    @PartTimeMonkey Před rokem

    This is an excellent video. Kudos to you.

  • @amac333
    @amac333 Před rokem

    really enjoyed this, thanks

  • @celkoken
    @celkoken Před rokem

    Thank you for this!

  • @faiyazibrahim9457
    @faiyazibrahim9457 Před rokem

    The best explanation I've ever seen.

  • @pove4266
    @pove4266 Před rokem

    I was making a racing game as my project for finishing my degree. I will throw it away and start again copying what u did. Man if I can pull this off I think it is great. What a great explanation.

  • @yogihermawan1181
    @yogihermawan1181 Před 4 měsíci

    Thank you very much for providing such valuable knowledge for FREE!
    I learned more from your video than any assets I've paid.

  • @andersencastaneda6080

    Amazing tutorial, you just get a new subscriber and a new player for very very valet.

  • @yammen
    @yammen Před rokem

    thank you so much this was soooooo helpful

  • @MecegguemMohamed
    @MecegguemMohamed Před rokem +1

    This is how tutorials should be made explaining the physics and a math behind it in simple way and then dive into coding part, Great Job

  • @AndersBergh
    @AndersBergh Před 6 měsíci

    Wow. this was amazing. Will def buy the game for me and the kids

  • @andrewsimmers8215
    @andrewsimmers8215 Před rokem +1

    Words can’t describe the brilliance of this video, but I’m leaving a comment to try and help appeal to the algorithm gods, (you guys should too!). You deserve hella love man, thank you.

  • @zapoutix
    @zapoutix Před rokem

    Very nice video ! thanks

  • @DougFromTheBayou
    @DougFromTheBayou Před rokem

    Brilliant video! I had come up with a similar raycast solution for my Ludum Dare entry for a scooter game, but I wasnt sure of the best approach for using it on a 4 wheel vehicle

  • @erikm9768
    @erikm9768 Před 7 měsíci

    Best tutorial on the subject on youtube!

  • @tom_dom
    @tom_dom Před rokem

    Absolutely amazing tutorial!
    I have 0 knowledge when it comes to Unity and C# coding, but this tutorial has helped me tremendously in understanding how to approach making a custom physics based car in Unity!
    For me it has helped a lot to ask chatGPT how to implement these functions into Unity which has allowed me to successfully create my own car in Unity now :)
    Thanks a lot for this extraordinarily well put together tutorial! ❤

  • @eldany_uy
    @eldany_uy Před 11 měsíci +3

    I am Unreal user and This example applies perfectly because you're not focusing on the Engine but in the overal physics concept. Great Video!!!! SUBSCRIBED!

  • @xellart
    @xellart Před 8 měsíci

    Excellent video!

  • @nurdi21
    @nurdi21 Před 3 měsíci

    Great tutorial!

  • @omarvision
    @omarvision Před 9 dny

    AWEEEEEESOME sauce!!! this tutorial is awesome man!1

  • @saiverx
    @saiverx Před rokem

    Such an awesome video

  • @teo-1
    @teo-1 Před rokem +1

    thank you so much

  • @ThwackStudio
    @ThwackStudio Před rokem

    You are mega awesome thanks!!!

  • @Bardent
    @Bardent Před rokem

    I loved this video!

  • @xanderlinhares
    @xanderlinhares Před rokem

    I love these videos so much I bought the game.

  • @hakanviajando
    @hakanviajando Před rokem

    Amazing video.

  • @aliashrafi2063
    @aliashrafi2063 Před 5 měsíci +1

    19:12 Lost it when I saw the eyes :DDDD. Awesome Guide!!

  • @ZooHair
    @ZooHair Před rokem +1

    Just wow 👏

  • @JohbVb
    @JohbVb Před rokem

    Its a very cool tutorial🤘

  • @tehsimo
    @tehsimo Před 9 měsíci

    excellent video!

  • @drachenblut_m
    @drachenblut_m Před 8 měsíci

    Gonna buy a copy of this game now because this guide is exactly what I needed for the physics of my hover racer lol

  • @billycombo8298
    @billycombo8298 Před rokem

    Pretty sick stuff! Using the raw code won't get you 100% there but it's perfect for the basic premise.

  • @Xorked
    @Xorked Před 5 měsíci

    These videos should be used in universities, such great visuals and explanations.

  • @PicnicsPete
    @PicnicsPete Před 5 měsíci

    This has completely flipped how i'm approuching doing my car physics now. The way you've done the presentation is also amazing, clear, well illustrated and straight to the point. I can't commend you guys enough for this break down and the others you've done. Where can I sign up for your patreon of Unity tips :D

  • @RoffeDH
    @RoffeDH Před rokem +1

    This is they type of dev videos I'm looking for right now in my journey. Thank you so much for this! Will recreate what you've said here and put it on my Git project.

  • @jabnakarramon5121
    @jabnakarramon5121 Před 10 měsíci

    thank you man thank you

  • @EvanLandry
    @EvanLandry Před rokem

    This is so odd, I love it.

  • @ruchirraj5300
    @ruchirraj5300 Před rokem +3

    Your deep dive videos and blogs have really helped a lot!
    Thanks for this yet another helpful video ☺️

    • @ruchirraj5300
      @ruchirraj5300 Před rokem

      Although I'm curious how you made the visualization for the video, like the spring and everything 🤔

    • @ToyfulGames
      @ToyfulGames  Před rokem +4

      @@ruchirraj5300 It was all made in Unity in order to make this video! We joke that Unity is our "After Effects" that we actually know how to use.

    • @ruchirraj5300
      @ruchirraj5300 Před rokem

      @@ToyfulGames I have one more question, for the rotation of tires do you just ignore any case where it could slip(in forward direction), and accordingly, do you just rotate the wheels based on velocity of the car or based on the force applied? 😅

    • @ToyfulGames
      @ToyfulGames  Před rokem +3

      @@ruchirraj5300 we look at the movement of the car from the previous frame, and calculate the amount of tire rotation based on the radius of the tires, and accumulate the tire's rotation based on that. if the e-brake is on, we stop rotating the tires so it looks like they lock up.

    • @alexba838
      @alexba838 Před rokem

      @@ToyfulGames Good afternoon, I have a question. The character has an animation of interaction with the environment, he needs to open the chest. But we can approach the chest from any side, even to the left, even to the right, and the opening animation must be started strictly from one position. How to correctly move the character from the current position to the animation start position? Use inversion kinematics + pathfinding or are there other ways?

  • @aaronh560
    @aaronh560 Před 2 měsíci

    This is brilliant. I'm currently fighting with wheel colliders to get the exact semi-realistic arcade-like feel that I want - with predictable controls to be able to increase stats over time without the physics of the car going haywire and it's driving me potty

  • @3DMVR
    @3DMVR Před rokem

    smart game idea, not really into the diner dash type stuff but driving is fun, and you can mess with ppl, would be cool with flight too

  • @timvandeneng4724
    @timvandeneng4724 Před 8 měsíci

    Ilearned a lot! thanks!

  • @TruckerJoeOfficial
    @TruckerJoeOfficial Před rokem

    Really the best tutorial for car forces I have ever seen! Thank you very much!
    Anyone has a tip how to get the steering smoothly?

  • @ruka1973
    @ruka1973 Před měsícem

    You could become the new "brackeys". You really have a great talent for tutorials

  • @karim009
    @karim009 Před rokem

    Bought the game on the switch!
    And you should start making more unity tutorials like that, this channel could grow so much!
    Or some udemy courses too!