Thank you for the tutorial! It is very helpful :) I would like to see more tuts like this! And your blueprints are very great and helpful! 👍😁 6:11 - Importing model and setting up scene 10:50 - Car painting in unity 12:39 - Adding rigid body + collider 14:18 - Teaching about raycast & suspension through blueprint 19:05 - Adding origins for suspensions 21:20 - Adding mass to rigid body 21:57 - Making the script 41:03 - Last line of script 41:15 - Testing the script and experimenting with it I recommend to watch whole video because there are a few tips that are helpful. I just wanted to provide quick walkthrought. :)
@blinkachu4044 жыл бұрын
Thank you for the timestamps, that's really helpful
@workflowinmind4 жыл бұрын
@@blinkachu404 If you copy-paste exactly Oliver's comment in the description, the timestamps will be embedded in the player. It would be easier for long videos like these. Thanks for the content ;)
@Kosoku633 жыл бұрын
heres the code for this tutorial: (keep in mind, some values need to be changed to fit your game using System.Collections; using System.Collections.Generic; using UnityEngine; public class ScriptWheel : MonoBehaviour { private Rigidbody rb; [Header("Suspension")] public float restLength; public float springTravel; public float springStiffness; public float damperStiffness; private float minLength; private float maxLength; private float lastLength; private float springLength; private float springForce; private float damperForce; private float springVelocity; private Vector3 suspensionForce; [Header("Wheel")] public float wheelRadius; void Start() { rb = transform.root.GetComponent(); minLength = restLength - springTravel; maxLength = restLength + springTravel; } void FixedUpdate() { if (Physics.Raycast(transform.position, -transform.up, out RaycastHit hit, maxLength + wheelRadius)) { lastLength = springLength; springLength = hit.distance - wheelRadius; springLength = Mathf.Clamp(springLength, minLength, maxLength); springVelocity = (lastLength - springLength) / Time.fixedDeltaTime; springForce = springStiffness * (restLength - springLength); damperForce = damperStiffness * springVelocity; suspensionForce = (springForce + damperForce) * transform.up; rb.AddForceAtPosition(suspensionForce, hit.point); } } }
@victorfiy98442 жыл бұрын
god bless you man
@meehdrescher2 жыл бұрын
you are doing the lords work!
@violettracey3 ай бұрын
Thank you!
@TotallyNotInspired3 жыл бұрын
After 2 jears still the best Tutorial on car physics in Unity :D
@januszhrust Жыл бұрын
Awesome work, thank for this. I was searching for info about raycasting physics for car, and you've made it before many tutorials I've seen lately, congards! I hope you doing great!
@stephenwest34623 жыл бұрын
Fantastic explanation. Appreciate the visual explanations and diagrams provided before writing the code. This is an easy-to-implement solution.
@MacJetHD Жыл бұрын
YOU EXPLAIN SOO GOOD. Liked and subscribed. Ty for this tutorial.
@lee1davis14 жыл бұрын
Wish you made more tuts. You are a good teacher.
@donperera70535 жыл бұрын
Love The Car Physics Videos, would love to see a whole game made out.
@blinkachu4045 жыл бұрын
Hehe, that's way too much work for just 1 person ^^; This tutorial will just focus on getting the car physics to work so people can use that in their own games :) Thanks for the comment though!
@savdhariyasanjay49624 жыл бұрын
@@blinkachu404 Can you help to create Steer Assistant for a custom complete Car Physics.
@ZeroSleap3 жыл бұрын
@@blinkachu404 What about two people?
@tommo1202 жыл бұрын
@@ZeroSleap What about THREE people?! ;)
@gordonbeeman53873 жыл бұрын
put this into the ScrWheel.cs to visualize a bit what's happening private void OnDrawGizmos() { Gizmos.color = Color.green; Gizmos.DrawLine(transform.position, transform.position + transform.up * -springLength); Gizmos.color = Color.red; Gizmos.DrawWireSphere(transform.position + transform.up * -springLength, wheelRadius); }
@exe.stopped2442 жыл бұрын
for anyone having problems with car being pulled down on jumps, make the maxLenght the same as restLenght. (just remove spring travel and make min and max public and restLenght = maxLenght)
@deniial004 жыл бұрын
Sad to see this series already ended!
@blinkachu4044 жыл бұрын
It hasn't ended, it's on a hiatus for now that's all ^^
@djotzi78985 жыл бұрын
Great Tutorial! Good alternative for Wheelcollider
@cptray-steam Жыл бұрын
I would love to know how to make a visual representation of the suspension moving up down, reacting to the compressing of the wheel collider's suspension. The only thing I have been able to find on it is a video where someone was controlling it through animation. Which boggles my mind at how you can maybe make a bone reacts to the wheels moving up and down. But it was a demonstration and not a tutorial.
@bulent24352 жыл бұрын
This is the best by far.
@minigator210 ай бұрын
Thank you so much! A very good starter guide even into 2024! Such a good video 🫶
@DerAua4 жыл бұрын
Wow, I love the spring script. This can help me get rid of the horrible Unity wheel collider and get me more control over my creation. You saved me so much research! Even though I will read up on the spring physics regardless.... :-)
@SpookieD00kie4 жыл бұрын
I have been looking for a tutorial or help for car physics that doesn't use the wheel collider. This has to be the only one I have found, it's perfect!
@streetlogic2 жыл бұрын
Press shift and F key it'll follow the selected object in scene view
@Dacommenta3 жыл бұрын
Niceeee. I own a mk4, always cool to see one of my JDMs in tutorials
@tommo1202 жыл бұрын
Alright, no need to flex! Love that car though, you're lucky and I am totally not incredibly jealous...
@jonihan332 жыл бұрын
Thank you for the tutorial! Nice to get someone to really explane things really well and visualize this too! Its easy to make typing error with word "Length" and agree naming with rest! :D
@Skipzilla01 Жыл бұрын
the swearing makes you more relateable. Thumbs up from me
@ruslankoller98914 жыл бұрын
Huge thanks and good luck with your project 👍
@slciz94603 жыл бұрын
oh dani got this from here :)
@ahmadzuhdi94504 жыл бұрын
thank you for this tutorail. I can learn so many things
@orlandoguerrero70894 жыл бұрын
Hello, thanks for the tutorial. I have a problem, the "out RaycastHit hit" part of the if is throwing an error: "RaycastHit is a type but is used as a variable". I'm using Unity 2019 1.1. Any ideas? Thanks!
@orlandoguerrero70894 жыл бұрын
Solved it. I had to create a new RaycastHit before using the if statement. RaycastHit hit = new RaycastHit(); if (Physics.Raycast(transform.position, -transform.up, out hit, maxLength + wheelRadius)) { }
@TerrorVisual4 жыл бұрын
I also have this problem.
@dulladulla41344 жыл бұрын
@@orlandoguerrero7089 be blessed bidie,i didn't spleep the whole 9t figuring out what the heck
@shrippie-42143 жыл бұрын
A russian person also helped me make a racing game
@nxidplease Жыл бұрын
Question, did you face an issue where the suspension would bounce around slowly increasing the compression on each spring until it's too much and the car flips upside down?
@tommo1202 жыл бұрын
Great video! Really helped me understand how to get started implementing vehicle physics :D
@skaruts3 жыл бұрын
I heard people say that you can cast shapes (cylinders, I guess) instead of rays, to fix the issues with wheels sticking into things. Have you ever tried that kind of thing?
@brandonbennett30825 жыл бұрын
How is it guaranteed that RestLength is always greater than the SpringLength? You say so around 30:00 into the video, however looking at the calculation this doesn't really make sense. RestLength is simply some nonnegative constant, and the Raycast Length is (basically) RestLength + SpringTravel + WheelRadius. SpringLength is Raycast Hit - WheelRadius, and let's assume the farthest away raycast hit of just RestLength + SpringTravel + WheelRadius. This means that SpringLength, in this instance, is (RestLength + SpringTravel + WheelRadius) - WheelRadius or just RestLength + SpringTravel. So, in this instance, the RestLength - SpringLength ends up being RestLength - (RestLength + SpringTravel), where it is obvious that SpringLength is GREATER than RestLength, making a negative value for SpringForce. This is foreseeable for any value of the raycast hit that is greater than RestLength. I don't really understand. Any response appreciated, thanks.
@blinkachu4044 жыл бұрын
Sorry, I can't really make heads or tails of your question. Restlength is a static value, springlength is the value of length of the hit.distance, it's not restlength + springtravel the hit.distance is the distance of the raycast before it hits the ground minus the wheelradius to just get the actual springlength
@gileee4 жыл бұрын
@@blinkachu404 In the case where the suspension is extended past it's restLength this script will apply a downward force on the car. So this script basically simulates the car's suspension being bolted to the ground. Also, clamping the spring length doesn't stop the car body from continuing to move in the same direction, only limits the spring force applied to it.
@ShivamRajawat4 жыл бұрын
Anyone got solution to this?
@gileee4 жыл бұрын
@@ShivamRajawat I made it so my spring has a length and force is applied only when the spring is compressed (current length less than rest length)
@ShivamRajawat4 жыл бұрын
Thanks will try that
@SubjektDelta4 жыл бұрын
Really thought this is going to be with wheel colliders but you are AMAZING for going the long route because i cant use them!!!
@SanVas13379 ай бұрын
Did everything as in the video tutorial, but my wheels fall under the ground and the car lays its collider on the ground, why? @BlinkAChu
@ilikecakeandbiscuits Жыл бұрын
Amazing stuff, thanks!
@michele96433 жыл бұрын
Awesome video man! :)
@erikm9768 Жыл бұрын
I love this, but wish it was possible to do with a is kinematic rigidbody instead
@zimi9925 жыл бұрын
This is amazing, thanks a lot.
@chocobochick53905 жыл бұрын
I've already pretty much posted this on similar videos but is there a way you can keep the "stick to the ground" arcade physics, the uphill and down hill speed, lose the car wobbling and shaking when it lands, and use that for a character in a 3d platformer? I'm in the process of making something like outrun (or 3D arcade racer) where you can attack. So you remove the spring physics. How would you always land on your feet? So instead of rotating and twisting like a car once you land you land straight up on your feet?
@blinkachu4045 жыл бұрын
In that case you'd remove all actual spring code, and all you'd have to do is something along the lines of if (Physics.Raycast(transform.position, -transform.up, out RaycastHit hit, 1f) { isGrounded = true; } else { isGrounded = false; } then you can use the isGrounded boolean to set whether you want to apply gravity to your character or not. How to always land on your feet regardless of angle is something I don't know, then you'll probably want to search for videos on planet gravity in Unity.
@chocobochick53905 жыл бұрын
@@blinkachu404 k thanx
@AkshayKumar-iy4gg3 жыл бұрын
This is Really good
@parinamais Жыл бұрын
thank you so much for this tutorial!!
@artinstroukeprod4 жыл бұрын
Great tutorial! Thank you! very helpfull!
@violettracey3 ай бұрын
I am getting the error "feature 'declaration expression' cannot be used because it is not part of the C# 4.0 language specification" When I double click it it takes me to the line with if (Physics.Raycast(transform.position, -transform.up, out RaycastHit hit, maxLength + wheelRadius)){ Edit: Another comment had a fix for this. You have to add RaycastHit hit = new RaycastHit(); above the if statement and remove the RaycastHit from it so you end up with RaycastHit hit = new RaycastHit(); if (Physics.Raycast(transform.position, -transform.up, out hit, maxLength + wheelRadius)) { }
@oynamalikanal35053 жыл бұрын
Did someone teach you this, or did you learn it yourself? I'm just curious about how people learn
@ShakerFS Жыл бұрын
You are amazing, thank you! 🙏
@jfelrod19602 жыл бұрын
Excellent tutorial!!! Thank you so much 😊
@nenebaez41454 жыл бұрын
Hi, could you do more physics tutorials for helicopter trucks and how to add different fvx sounds of engine brake
@lucapagano36853 жыл бұрын
Question, any percent relative to the weight of the car to set the spring stiffnes and the damper stiffnes properly?
@ChiouPika Жыл бұрын
it helps me a lot thanks
@samyam2 жыл бұрын
thank you ⭐
@EngiNetion5 жыл бұрын
Subbed! Nice tutorial
@blinkachu4045 жыл бұрын
Appreciate it ^^
@EngiNetion5 жыл бұрын
@@blinkachu404 Will more tutorials come?
@brandondoucet12364 жыл бұрын
The .fbx file contains the wheels and other models of the supra. What free software could you use to separate the 3D models?
@blinkachu4044 жыл бұрын
Blender would probably be your best option :)
@ProceduralWorldLab5 жыл бұрын
I'm mainly UE4 user but I watch your Unity tutorial and want to translate to UE4.
@ScotttyJay5 жыл бұрын
Same. There is a great UE4 tut but it’s in the chez. Hold up. Did she just say she is doing the chez one .. 👍
@blinkachu4044 жыл бұрын
@@ScotttyJay Yes, the one I followed was from Иван Новожилов, but as it's in Unreal and I don't speak Russian (or Chez, I could be wrong on that?) I had to manually translate everything into code by understanding the thought pattern rather than just rewriting the code.
@kafif284 жыл бұрын
@@blinkachu404 Иван Новожилов speak on russia)
@rvbzero72 жыл бұрын
what is the physics term of the line from the cv axle to the ground?
@ahmd-salh4 жыл бұрын
That was very helpful thank you.
@the1jdude2 жыл бұрын
How do I substitute wheelRadius with an actual wheel so that I could see the wheels bounce with the suspension?
@gaming_reaper_10023 жыл бұрын
when i try to drag the script into the wheels thing it comes up "can't add script behavior CallbackExecutor. The script needs to derive from MonoBehaviour!" have you any idea on how to fix this?
@shurahbeeltariq74592 жыл бұрын
I haven't encountered that before; my guess would be that you somehow changed the "Parent" class where your script name goes. Make sure that "MonoBehavior" is there and spelled correct(case sensitive) after the colon. Like the following example code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class YourScriptNameHere : MonoBehaviour { }
@kacperNFS4 жыл бұрын
Hey, I love this series and I wanted to try to incorporate it into my godot project, but the physics that I get seem way off, do you think that it is a problem with my code or do the Godot and Unity physics engines differ so much that it would require some big changes? Sadly godot is lackluster in the vehicle physics tutorials, and especially the raycasts.
@blinkachu4044 жыл бұрын
Unfortunately I've never worked with Godot so I really don't know. I haven't tested the code in other engines, but theoretically it should work, since the physics are based on real life mathematical equations. You may want to lower the values though, it could be that GODOT uses different values than Unity. Unity uses 1 meter for 1 unit.
@proigr4 жыл бұрын
idk why but I have to use transform.right "(0, 1, 0)", instead of transform.up "(1, 0, 0)". Otherwise the object just leans to its side
@proigr4 жыл бұрын
Oh I figured it out, my Suspension gameobjects were rotated on the Z axis by 90 degrees
@proigr4 жыл бұрын
could someone tell me what will happen if I use Vector3.up instead of transform.up ? How will this change effect the object's behaviour ?
@blinkachu4044 жыл бұрын
This would mean that you'd always use the World's Up vector, rather than the car's Up vector. In other words, if the car is on its side, on its roof or whatever, the suspension will not work the same way. You wouldn't be able to go through loops for instance (just an example)
@KiZhuGames Жыл бұрын
Car is sliding on inclined surface. Does someone know how to fix this?
@takumi_fujiwara32503 жыл бұрын
Hello i have a problem i wrote everything and my visual studio says that "=" is not a valid expression term
@L3RNA3AN3 жыл бұрын
Anyone else surprised to see Dani in the comment section?
@stupidgameplay8092 жыл бұрын
I searched so long for this haha
@skewd25283 жыл бұрын
Thank you!
@lwaneletiyani70604 жыл бұрын
can you please show us how to make the wheel colliders steer slow
@blinkachu4044 жыл бұрын
This is not a tutorial with wheel colliders, so unfortunately I can't
@mathew32672 ай бұрын
How do I rotate tires?
@varunchib-b4 жыл бұрын
Awesomeeee...Please keep making videos like this..I've subbed You..:-)
@kafif284 жыл бұрын
when i added damper, my car twitches, but if i set damper stiffness to 0, car behaves normally(without damping) rb mass: 1205kg spring stiffness: 30000 damper stiffness: 4000 how i can fix it?
@LemonMontage4203 жыл бұрын
Its possible that you're calculating lastlength after springvelocity, it should be the other way around: 1. lastlength = springlength; 2. springvelocity = (lastlength - springlength) / Time.fixedDeltaTime; Doing it the other way around means that you're calculating the current length of the spring, rather than the last length (which is what we want). Hope this helps!
@dougperson29305 жыл бұрын
This is such an awesome tutorial and very well explained Blinkachu! I have one question though. I am getting very different results for my mass setting. you have 1410 and I had to bring mine down to 50 to get even close to similar results as your bounce. I did not use your exact model. Any reason you can think of for this?
@blinkachu4045 жыл бұрын
Maybe your physics settings are not setup correctly in Unity? Or maybe a calculation or something that isn't quite right? (I have that happen sometimes when I follow a tutorial haha) Other than that I honestly wouldn't know, I've remade these physics three times in both Unity 2018 and Unity 2019 and have no issues with them :/
@HussainAhmad-b9u13 күн бұрын
where are you now
@serkan61853 жыл бұрын
what does it mean spring travel
@jeffreyalphonso4 жыл бұрын
Hi for some reason I can't get my code to register the header or the rigidbody. It just stays white. Is there a way to fix that or am I doing something wrong?
@blinkachu4044 жыл бұрын
You mean in VisualStudio itself, that when you type the Rigidbody call and the Header call stay white? That means your VisualStudio is not linked to your Unity profile. Not sure how to fix it though, I would google that issue as there are solutions out there.
@jeffreyalphonso4 жыл бұрын
@@blinkachu404 I tired it and it worked. Thanks for the help. Idk how I missed a simple fix like that
@sofusser4 жыл бұрын
I swear to God brother, this is a great tutorial and this is not your fault, but I have been trying to get this to work for hours. I have copied your code exactly, been messing with the constants, I have been searching the deepest pits of the API for an explanation. First I thought maybe i wasn't referencing the rigidbody correctly, but i found out I was doing it correctly. I found out how to do Debug.Drawray to see if maybe it didn't properly register the collision, but no it definetaly was all correct. Just every single time for the last few hours when I pressed play, the damn car just fell flat on the ground. Wanna know what I did wrong? Fucking spelled FixedUpdate wrong I had it as fixedUpdate. GOD. Didn't give me any errors either.
@blinkachu4044 жыл бұрын
Yeah, Update and FixedUpdate both won't give you errors on their own haha. But Update is only limited by how fast your PC is, while FixedUpdate is limited by an internal physics update interval, so FixedUpdate should be used for all physics related code ^^ Good to hear you found out what it was
@that_kaii3 жыл бұрын
i had this happen,check your mass on the rb
@parinamais Жыл бұрын
this comment has just spared me quite a few hours of stress. THANK YOU VERY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!
@TwistersSK84 жыл бұрын
The car accelerates forever. Works like a hover. I'm trying to figure out how to solve it.
@mucahitdemirci95773 жыл бұрын
Great
@powersx25084 жыл бұрын
How can i get rid of sliding problem? it slides so much.
@blinkachu4044 жыл бұрын
It slides because there is no forward and sideways friction. We've only calculated 1 axis so far, which is the up axis, and only calculates the suspension. There's no friction, therefore the car slides (imagine a car on ice)
@powersx25084 жыл бұрын
@@blinkachu404 I will think on that
@TerrorVisual4 жыл бұрын
Could you share your reference images?
@blinkachu4044 жыл бұрын
Here's a link to all of them in an album: imgur.com/a/EcrvHK1
@swordsmanhmd13533 жыл бұрын
my car is vibrating after doing everything you thought and i cant seem to have a fix, someone HELP!
@besniknurshaba19214 жыл бұрын
where is the 4 th video bro
@mr.ak.nation89874 жыл бұрын
I wanna make a game for Android or ios whatever. Can help? Can make tutorials for that. There is no tutorials for phones really. (Not much)
@Raindrop7882 жыл бұрын
"It can help to see the raycasts in the scene view while its running, if you want to see that try adding this in your if statment:" Debug.DrawRay(transform.position, -transform.up * hit.distance, Color.red); "And add an else statment with" Debug.DrawRay(transform.position, -transform.up * (springTravel + wheelRadius), Color.yellow); "This allows you to see the raycast and is it is in contact with something"
Great video but it could have been 20 minutes shorter if only you decided that some things aren't worth adding extra information on. "But if you don't have 47 minutes to understand a car script-" I do, but if I wish I could have spent less time on it. Keep it essential.
@UnderdogDen3 жыл бұрын
mmm good tutorials
@j3rm81ne5 жыл бұрын
Do you still have the slides?
@blinkachu4045 жыл бұрын
I do :) Here's a link to all of them in an album: imgur.com/a/EcrvHK1