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

Поділитися
Вставка
  • Опубліковано 1 чер 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
  • Ігри

КОМЕНТАРІ • 386

  • @kalkatos
    @kalkatos Рік тому +163

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

  • @f11bot
    @f11bot Рік тому +226

    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 Рік тому +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 Рік тому +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 Рік тому +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 Рік тому

      @@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 Рік тому +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 Рік тому +41

    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 Рік тому +57

    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.

  • @williamchurch8401
    @williamchurch8401 Рік тому

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

  • @chienbanane3168
    @chienbanane3168 Рік тому

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

  • @oldshamen
    @oldshamen Рік тому +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.

  • @QuadeZaban
    @QuadeZaban Рік тому +1

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

  • @lucaswk
    @lucaswk Рік тому

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

  • @reversible8740
    @reversible8740 Рік тому +6

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

  • @reihanmohamed6718
    @reihanmohamed6718 Рік тому

    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.

  • @boulder_dude
    @boulder_dude Рік тому +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!

  • @tageueland
    @tageueland Рік тому

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

  • @blinkachu5275
    @blinkachu5275 Рік тому

    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

  • @neipo
    @neipo Рік тому +1

    Such a good series thank you for making these

  • @ririgamesofficial
    @ririgamesofficial Рік тому +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.

  • @jojo.s
    @jojo.s Рік тому

    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 6 місяців тому

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

  • @guadog
    @guadog Рік тому +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!

  • @andrewalex478
    @andrewalex478 Рік тому

    Very satisfying and useful video tutorial! Great job!

  • @torryjaja
    @torryjaja Рік тому +1

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

  • @OddStare
    @OddStare 5 місяців тому

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

  • @LuRybz
    @LuRybz Рік тому +1

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

  • @Brovioli
    @Brovioli Рік тому +14

    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.

  • @ElvishJumpSuit
    @ElvishJumpSuit Рік тому

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

  • @luisfidalgo9128
    @luisfidalgo9128 4 місяці тому +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!

  • @Bloodlinedev
    @Bloodlinedev Рік тому +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.

  • @juanloutech2864
    @juanloutech2864 Рік тому

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

  • @ravendave24
    @ravendave24 Рік тому

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

  • @dziemon
    @dziemon Рік тому +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!

  • @MineXplayPL
    @MineXplayPL 11 місяців тому

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

  • @piyushguptaji402
    @piyushguptaji402 Рік тому +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

  • @devin18101
    @devin18101 Рік тому +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.

  • @ChillGuyYoutube
    @ChillGuyYoutube Рік тому +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!

  • @tokyowarfare6729
    @tokyowarfare6729 Рік тому

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

  • @sethsandwich
    @sethsandwich 3 місяці тому

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

  • @f1van405
    @f1van405 Рік тому

    Great job! Thank you very much for your tutorials!

  • @psychedeliccoffee2737
    @psychedeliccoffee2737 4 місяці тому +1

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

  • @Glados44
    @Glados44 9 місяців тому

    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!

  • @drewbluewasabi
    @drewbluewasabi Рік тому

    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!

  • @user-ly3fs9jl2p
    @user-ly3fs9jl2p Рік тому

    so much effort for tutorial. great work

  • @bovineox1111
    @bovineox1111 Місяць тому

    This is a great solution. Love it.

  • @ragerungames
    @ragerungames Рік тому

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

  • @mrskomps
    @mrskomps 7 місяців тому

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

  • @Vsev0l0d
    @Vsev0l0d Рік тому

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

  • @haikunHuanghk
    @haikunHuanghk Рік тому

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

  • @PartTimeMonkey
    @PartTimeMonkey Рік тому

    This is an excellent video. Kudos to you.

  • @gregoryhause00
    @gregoryhause00 Рік тому

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

  • @bismarckyjag
    @bismarckyjag Рік тому

    Thank you very much for sharing your knowledge!

  • @DovyBL
    @DovyBL 11 місяців тому +1

    Best car physics video ever! ♥

  • @tropochito
    @tropochito 9 місяців тому

    GOD, What AMAZING TUTORIAL!

  • @redsunpro
    @redsunpro Рік тому +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 🙂

  • @victorbarreto1067
    @victorbarreto1067 Рік тому +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".

  • @rahulcorleone4222
    @rahulcorleone4222 Рік тому

    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 Рік тому

    Brilliant breakdown!

  • @faiyazibrahim9457
    @faiyazibrahim9457 Рік тому

    The best explanation I've ever seen.

  • @lionn00b
    @lionn00b 10 місяців тому

    awesome video! really helpful, thank you.

  • @ruchirraj5300
    @ruchirraj5300 Рік тому +3

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

    • @ruchirraj5300
      @ruchirraj5300 Рік тому

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

    • @ToyfulGames
      @ToyfulGames  Рік тому +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 Рік тому

      @@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  Рік тому +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 Рік тому

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

  • @marekhusenica3400
    @marekhusenica3400 Рік тому

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

  • @MecegguemMohamed
    @MecegguemMohamed Рік тому +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

  • @pove4266
    @pove4266 Рік тому

    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.

  • @RoffeDH
    @RoffeDH Рік тому +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.

  • @geri4367
    @geri4367 Рік тому +1

    This is so sooo soooooo good. Thank you so much

  • @eldany_uy
    @eldany_uy 10 місяців тому +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!

  • @aliashrafi2063
    @aliashrafi2063 4 місяці тому +1

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

  • @andersencastaneda6080
    @andersencastaneda6080 Рік тому

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

  • @amac333
    @amac333 11 місяців тому

    really enjoyed this, thanks

  • @yogihermawan1181
    @yogihermawan1181 3 місяці тому

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

  • @erikm9768
    @erikm9768 7 місяців тому

    Best tutorial on the subject on youtube!

  • @yammen
    @yammen Рік тому

    thank you so much this was soooooo helpful

  • @andrewsimmers8215
    @andrewsimmers8215 Рік тому +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.

  • @AndersBergh
    @AndersBergh 6 місяців тому

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

  • @DougFromTheBayou
    @DougFromTheBayou Рік тому

    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

  • @xellart
    @xellart 8 місяців тому

    Excellent video!

  • @tom_dom
    @tom_dom Рік тому

    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! ❤

  • @zapoutix
    @zapoutix Рік тому

    Very nice video ! thanks

  • @nurdi21
    @nurdi21 2 місяці тому

    Great tutorial!

  • @celkoken
    @celkoken Рік тому

    Thank you for this!

  • @Xorked
    @Xorked 4 місяці тому

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

  • @saiverx
    @saiverx Рік тому

    Such an awesome video

  • @PicnicsPete
    @PicnicsPete 4 місяці тому

    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

  • @xanderlinhares
    @xanderlinhares Рік тому

    I love these videos so much I bought the game.

  • @JohbVb
    @JohbVb Рік тому

    Its a very cool tutorial🤘

  • @Bardent
    @Bardent Рік тому

    I loved this video!

  • @billycombo8298
    @billycombo8298 11 місяців тому

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

  • @Tankmin
    @Tankmin 4 місяці тому +3

    Hey, I just want to say thank you. This is a very great and concise guide to getting a raycast car set up :) I also appreciate you providing some source code.
    In my free time, I have been working on a car game as well, but mine involves high speeds and sharp turns and I ran into a lot of unique issues. For instance, I kept having to make my steering angle extremely small at high speeds to avoid the car flipping over, and this isn't the effect I wanted (also I probably still have some bugs left in my code). Here is some more information I would like others to learn and stopped me from endlessly testing magic numbers everywhere:
    - The base spring constant for your vehicle should be: mass * 9.8 / 4.0 / (half of the total spring length). The 9.8 comes from gravity, since -9.8 is the acceleration of gravity and you want to counteract it. Multiplying that by the total vehicle mass gives you the downward force the car will be applying to the suspension. Dividing that by 4 (number of wheels) means the wheels will equally support the weight of the vehicle. Dividing all that by half the length of the total length of the suspension means that the suspension will be trying to balance itself at half the suspension length. Now that you have all that, just take that value and scale if by some number between 0 and 1 for the desired spring behavior :)
    - If you want to be able for your car to have a sharper turn at high speeds without turning over, one thing you may want to research what is known as toe in and toe out. Basically, if the distance between the front tires is less than the distance in the back tires, that's toe in. Your steering will be less responsive at high speeds, but the tendency to flip over will be reduced if you turn at a high angle. Toe out is the opposite, the back wheels will be closer together than the front, your steering will become more responsive, and more likely to flip over. I think this is related to understeering and oversteering, I'm still learning though
    - You can look into ackermann steering or anti-ackerman steering to help you with various turning behaviors

    • @himanshugupta325
      @himanshugupta325 4 місяці тому +1

      Thank you for the information, recently I was in the same problem of getting desired values for the car.

    • @Tankmin
      @Tankmin 4 місяці тому

      Glad it helped! Today I learned that if you apply the tire friction forces at the center of mass, the car won't like to flip over. That way, at high speeds with sharp turns you won't flip over. I learned that from a Rocket League GDC presentation, and they mentioned that when you do that you lose all your body roll and the car looks boring and stiff. They just added that back in with animations. I tried it and that worked for me! And to add some body roll back in, I just lowered the location of those forces slightly (like by a distance of 0.02) in the direction of the wheels' y basis. That way, you still get the body roll, but it's much less pronounced and the car won't flip over.@@himanshugupta325

  • @erikhjortsater5461
    @erikhjortsater5461 27 днів тому

    I'm in the position where I know how to program, through university courses, and I know all the physics by heart, through my first uni engineering mechanics courses. But putting it all together and actually implementing it is such an exhausting task that I just end up watching UA-cam videos for the entertainment of it anyway!

  • @tehsimo
    @tehsimo 9 місяців тому

    excellent video!

  • @drachenblut_m
    @drachenblut_m 7 місяців тому

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

  • @hakanviajando
    @hakanviajando Рік тому

    Amazing video.

  • @misskongiii7141
    @misskongiii7141 Рік тому

    i feel like my mind's been expanded. amazing explanation of really complex stuff that i usually struggle with!!! thank you so much. if you have the time, i would appreciate any resources you used for learning how to implement lookup curves. is this a common programming technique or did you guys come up with this yourselves? anyways, thanks again for the amazing amazing video!

    • @ToyfulGames
      @ToyfulGames  Рік тому +3

      Lookup curves are pretty common, depending on the engine or technology you are using. Specifically in Unity, you implemented them in a script as an AnimationCurve variable. declating a public AnimationCurve in a MonoBehaviour will give you a nice little curve editor that you can adjust however you want. And then performing the lookup is as simple as doing myCurve.Evaluate(x), where X is the x-axis value, and it will return the Y value from the curve at that point. hopefully that helps!

  • @EvanLandry
    @EvanLandry Рік тому

    This is so odd, I love it.

  • @ThwackStudio
    @ThwackStudio Рік тому

    You are mega awesome thanks!!!

  • @OfflineOffie
    @OfflineOffie Рік тому +11

    Absolutely _Top_ quality tutorial right here. I loved all the visualizations and clear as day explanations of every single moving part!
    Thank you!

    • @Colonies_Dev
      @Colonies_Dev Рік тому

      i cant even fking figure out how to set up this code, because all the void public ~ etc functions, setup is missing.

    • @Colonies_Dev
      @Colonies_Dev Рік тому

      i am able to follow ALL other fucking tutorials, but not this one 😂 i've been fidget fking with raycasts for hours on my own trying to figure out how to levitate based on raycast distance from ground

    • @Colonies_Dev
      @Colonies_Dev Рік тому

      it focusses for 15 minutes on obvious facts, only to then show 2 seconds of incomplete code which just makes me have to think REALLY hard to see if i correctly set up the rest of the code, and i dont wanna spend 10 minutes type copying shit i dont understand. only for it to not work, because i didnt understand.

    • @Colonies_Dev
      @Colonies_Dev Рік тому

      EXAMPLE, carRigidBody.getpointvelocity(tiretranform.up), is the unity engine actually equipped with these strange keywords??? how much of this is values that were declared in advance, in the missing code????

    • @Colonies_Dev
      @Colonies_Dev Рік тому

      at 12:01

  • @shelikhann
    @shelikhann 3 місяці тому

    Очень полезный контент, это то, что было нужно!

  • @teo-1
    @teo-1 Рік тому +1

    thank you so much

  • @gamedevquest
    @gamedevquest 9 місяців тому

    you deserve to have your own million sub dev channel

  • @3DMVR
    @3DMVR Рік тому

    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

  • @aaronh560
    @aaronh560 Місяць тому

    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

  • @karim009
    @karim009 Рік тому

    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!