Simple Car Controller in Unity Tutorial

Ғылым және технология

[UPDATE] If you are looking for the breaking bugfix check the description after expanding it!
Let’s learn how to create a car controller in Unity. We will get to know Unity’s wheel collider component and use it to move a car. We will also create a simple camera script that will follow the car.
[BREAKING BUGFIX!!]
There is a bug in the HandleMotor() method in the CarController.cs. The "if (isBreaking) check should be removed. The fix is also pushed to the GitHub repository. The method should look like that:
private void HandleMotor()
{
frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
frontRightWheelCollider.motorTorque = verticalInput * motorForce;
currentbreakForce = isBreaking ? breakForce : 0f;
ApplyBreaking();
}
Used assets:
ARCADE: FREE Racing Car
assetstore.unity.com/packages...
by: iMENA Games
assetstore.unity.com/publishe...
Grab the whole project from GitHub:
github.com/GameDevChef/CarCon...

Пікірлер: 687

  • @Massive-3D
    @Massive-3D3 жыл бұрын

    I was so afraid to scroll down and see "video upload date: 5 years ago" Subscribed!

  • @uniquelyrics2331

    @uniquelyrics2331

    3 жыл бұрын

    lol

  • @matheusmartins3177

    @matheusmartins3177

    3 жыл бұрын

    me too LOL

  • @monkeyrobotsinc.9875

    @monkeyrobotsinc.9875

    3 жыл бұрын

    i HATE that.

  • @SajeehSamad

    @SajeehSamad

    3 жыл бұрын

    lol

  • @RandomNovaGames
    @RandomNovaGames3 жыл бұрын

    Maybe the first video that I have seen that teaches you to create a nice car handling for free. Good place for me to start. Others dont handle well at high speeds

  • @T0MM0-Lds
    @T0MM0-Lds2 жыл бұрын

    As much as all the information is there and it's fantastic to use. Please remember this is a tutorial; not a speed run.

  • @hawkgamedev

    @hawkgamedev

    2 жыл бұрын

    there is also "Playback Speed" and "pause the video" you know ...

  • @T0MM0-Lds

    @T0MM0-Lds

    2 жыл бұрын

    @@hawkgamedev wow thanks! Never knew that was there! ❤️ Pillock

  • @hawkgamedev

    @hawkgamedev

    2 жыл бұрын

    @@T0MM0-Lds you are welcome poor fish.

  • @himanshuVisuals

    @himanshuVisuals

    2 жыл бұрын

    my car dont turn left and right

  • @hawkgamedev

    @hawkgamedev

    2 жыл бұрын

    @@himanshuVisuals hey man share in your discord I'll help you.

  • @drewvananne1796
    @drewvananne17963 жыл бұрын

    Exactly what I was looking for, great tutorial!

  • @MphasieMusic
    @MphasieMusic2 жыл бұрын

    OMG THANK YOU! You saved my project

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

    Thank you so much. It's fast and efficient as needed.

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

    This is really awesome video for newbie! Everyone in the youtube just skips parts of how to setting up the objects and not fully explain how each code works. But this video is really kind to explain how to take each steps!!

  • @eleanordare9350
    @eleanordare93502 жыл бұрын

    very clear and solved all my problems, thanks so much :-)

  • @Twiney_
    @Twiney_2 жыл бұрын

    This is my first time coding and it works great thanks dude!

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

    It works pretty good. Thank you!

  • @anonymousa7030
    @anonymousa70303 жыл бұрын

    THANK YOUU!! it is very simple and helpful

  • @luiss.2005
    @luiss.20053 жыл бұрын

    I really like this tutorial because you show some common mistakes and how to avoid them. For example: setting the box collider incorrectly or using Lerp insead of SmoothDamp. Unity is not a black box where you input the correct values and everything works just fine. Making games (or anything, really) is iterative. I think showing the process can be very encouraging for beginners.

  • @joooosl

    @joooosl

    2 жыл бұрын

    What did you use in HandleRotation? There is no SmoothDamp

  • @luiss.3866

    @luiss.3866

    Жыл бұрын

    Are we brothers?

  • @omegapirux
    @omegapirux4 жыл бұрын

    Very nice tutorial !

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

    Cool Nice and Straight Forward.

  • @BuoyEngine
    @BuoyEngine3 жыл бұрын

    Big thank you !! this is so useful video.

  • @arpitkhatana3675

    @arpitkhatana3675

    3 жыл бұрын

    Bro my car is rotating and flying can u help me.

  • @carolineyonatan216
    @carolineyonatan2163 жыл бұрын

    Lol i see this ad while watching dani

  • @swastikmishra8822

    @swastikmishra8822

    3 жыл бұрын

    Same bro

  • @vvixell4580

    @vvixell4580

    3 жыл бұрын

    same

  • @neongreggyyt1115

    @neongreggyyt1115

    3 жыл бұрын

    Same

  • @suanzalaltronsing4300

    @suanzalaltronsing4300

    3 жыл бұрын

    Ah. I see you're a Boner aswell.

  • @youdaily7113

    @youdaily7113

    3 жыл бұрын

    Ssssssnanananana same

  • @jonathankruse6941
    @jonathankruse69413 жыл бұрын

    thanks man it worked perfectly for me

  • @3bomb
    @3bomb2 жыл бұрын

    Just a quick heads up, this script is using negative motor torque to handle braking when pressing "S." Per Unity's documentation, negative motor torque should not be used for braking. If you'd like to apply brakeTorque instead of negative motorTorque, create an if statement that says if verticalInput < 0 then brakeTorque = -verticalInput * brakeForce.

  • @vilmerforsberg

    @vilmerforsberg

    Жыл бұрын

    in which part of the scrpit should you put this? btw i really liked your car video:)

  • @FC12CGaming
    @FC12CGaming3 жыл бұрын

    Omg thanks so much, i'm literally speechless that it actually works!!!!

  • @idkidc1885

    @idkidc1885

    3 жыл бұрын

    Hey man did u try it out on the new version of unity ?if yes does it work on the new version or only one the one he is using

  • @FC12CGaming

    @FC12CGaming

    3 жыл бұрын

    @@idkidc1885 no im using 2019.4

  • @FC12CGaming

    @FC12CGaming

    3 жыл бұрын

    @@idkidc1885 but it should work on the new unity

  • @idkidc1885

    @idkidc1885

    3 жыл бұрын

    @@FC12CGaming ok ty if it doesnot work on the new ill try that version

  • @FC12CGaming

    @FC12CGaming

    3 жыл бұрын

    @@idkidc1885 k

  • @atakankuloglu4877
    @atakankuloglu48772 жыл бұрын

    Great tutorial , thanks !

  • @theplaymakerno1
    @theplaymakerno13 жыл бұрын

    Got please you mate. This script is better than most of the bloated crap we find on the asset store.

  • @mythicaldriftz3357
    @mythicaldriftz33573 жыл бұрын

    Are you some sort of wizard man i have so much respect for you dude i have tried this and it works yes so to anyone wanna try just do it as he says

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

    Wow thk a lot for this video and the files in description

  • @gamedev_navneet
    @gamedev_navneet3 жыл бұрын

    Thank-you , this is working perfectly!👍

  • @HATL201
    @HATL2012 жыл бұрын

    Thanks a lot for the project dear.

  • @ramaarya3
    @ramaarya32 жыл бұрын

    Thankyou so much, you're lifesaver.

  • @mxq_wh1teangel288
    @mxq_wh1teangel2883 жыл бұрын

    One of the best tutorials ive seen so far 👍

  • @TheEdugato100
    @TheEdugato1003 жыл бұрын

    im a simple beginner, i just want my cube to move...

  • @froosx9418

    @froosx9418

    3 жыл бұрын

    well that's pretty easy i can actually send u the script if you'd like

  • @isaiahcancode2649

    @isaiahcancode2649

    3 жыл бұрын

    @@froosx9418 please show me

  • @isaiahcancode2649

    @isaiahcancode2649

    3 жыл бұрын

    nvm i already know how to

  • @DARK_AMBIGUOUS

    @DARK_AMBIGUOUS

    3 жыл бұрын

    Use bolt and then open the flow graph and make ad a thing called “on keyboard input” and then add a “position translate” thing and then make it so everyone you press W it moves the cube 1 on the x axis, and do the same thing with S but make it move -0.5 or -1 and then add a rotation translation thing and make it so it rotates 1 on the Z axis when you press A

  • @gamer-revolution

    @gamer-revolution

    3 жыл бұрын

    ok i am just like dani i only copy tutorials and not learn

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

    WOW! That was really cool😎😎

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

    Nice toturial!

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

    Thank you for tNice tutorials. You've done a great job breaking down the features and build. I can now concentrate on my instead of the

  • @walney2008
    @walney20083 жыл бұрын

    very good, I'm a beginner, I'm from Brazil, I learned to put the car in motion, thank you very much, would there be a video teaching you how to create a race track for you, have a lap counting system and checkpoints?

  • @blissweb
    @blissweb2 жыл бұрын

    I came here to see how to fix the purple car syndrome and you did that in the first minute. :-) Yay.

  • @retrogamer947
    @retrogamer9473 жыл бұрын

    NICE VIDEO quick n easy

  • @counterpointerz-rocketleag2038
    @counterpointerz-rocketleag20383 жыл бұрын

    thanks, you guys will definitely need to do some research about the different things he did, but coding is all about teaching yourself

  • @halivudestevez2
    @halivudestevez22 жыл бұрын

    Seems to be perfect, must try it. (I am lazy, so I will write a code that recognizes wheel colliders, and assign them to an array)

  • @rubenopenworld8405
    @rubenopenworld84053 жыл бұрын

    I mean yes you are doing things and i guess it works for experienced users of unity but you should explain more why you would do certain steps, idk when i would try this for some other thing i would not remember how to do it

  • @nahiyanalamgir7056

    @nahiyanalamgir7056

    3 жыл бұрын

    Agreed. I think the main problem is that these tutorial producers write code continuously without running the game to show the results at every step. Instead they probably just write the entire code at once before making the videos and copy every line from there, explaining each line lightly.

  • @monkeyrobotsinc.9875

    @monkeyrobotsinc.9875

    3 жыл бұрын

    im somewhat experienced and i still had to pause the video every 2 and a half seconds to catch up with the typing. hes crazy.

  • @dradex9562

    @dradex9562

    3 жыл бұрын

    @@monkeyrobotsinc.9875 you know he sped up that part right????

  • @samochreno

    @samochreno

    2 жыл бұрын

    @@monkeyrobotsinc.9875 you have to be kidding, if youre somewhat experienced you should be able to catch up with this easily

  • @gamesofarcadia
    @gamesofarcadia3 жыл бұрын

    Thanks a lot! It really helped for my next demo - subscribed twice!

  • @ahmedzarin2247

    @ahmedzarin2247

    3 жыл бұрын

    The best tutorial EVER

  • @erfanroghani
    @erfanroghani2 жыл бұрын

    Excellent tutorial, man! Super useful. But for my application, I need to ensure there is no rotation around the X-axis while applying the brake. How should I set the parameters?

  • @morpheus7422
    @morpheus74222 жыл бұрын

    Thanks for this video!

  • @keewinek
    @keewinek2 жыл бұрын

    Bardzo fajny poradnik :)

  • @ChrizSee

    @ChrizSee

    2 жыл бұрын

    @ TEKI335 actually yes

  • @szpinak2120

    @szpinak2120

    8 ай бұрын

    @@ChrizSee in polish no is yes

  • @faradheus
    @faradheus3 жыл бұрын

    Thank you my friend !

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

    I've found that changing suspension spring target position to 1 makes the car basically unable to flip over. or change it to 0 to make it super easy to flip :D

  • @gamedev_navneet
    @gamedev_navneet3 жыл бұрын

    I like your discipline while coding.

  • @monkeyrobotsinc.9875
    @monkeyrobotsinc.98753 жыл бұрын

    really cool that this worked, thanks, but i just used cinemachine for the follow camera.

  • @FelineRaptor-gv4te

    @FelineRaptor-gv4te

    2 жыл бұрын

    yeah, it would be more flexible actually because you can customize the value and get any behaviour you want. Also the cam look script in the video is not very comfortable while steering [same with standard assets cam look].

  • @SakthivelNadar
    @SakthivelNadar3 жыл бұрын

    This is sooo simple it reminds me physics and maths class not that much i ever attended to maths

  • @markpolak8622
    @markpolak86223 жыл бұрын

    You are missing the brakek force reset, the if(isBraking) {applybreak()} is wrong because, the 0f breakforce never applies, it means once you braked the car just stops and cant go anywhere, you shoul always apply the bake

  • @jacobpatron8387

    @jacobpatron8387

    3 жыл бұрын

    @PRANAY G.V. Inside the HandleMotor() function you could add this code to fix that bug, you may have already figured out a solution but hopefully it can at least help someone else. Basically, this code checks if isBreaking is false, if it is it sets the brakeTorque for each wheel to 0. if (!isBreaking) { frontRightWheelCollider.brakeTorque = frontLeftWheelCollider.brakeTorque = backRightWheelCollider.brakeTorque = backLeftWheelCollider.brakeTorque = 0f; }

  • @MrLiam111

    @MrLiam111

    3 жыл бұрын

    @PRANAY G.V. Just remove the IF from the ApplyBreaking method

  • @rahulprasad8906

    @rahulprasad8906

    3 жыл бұрын

    @@jacobpatron8387 thank you!

  • @tejaskale6823

    @tejaskale6823

    2 жыл бұрын

    @@jacobpatron8387 thankyou soooo much dude

  • @bamers404

    @bamers404

    2 жыл бұрын

    @@jacobpatron8387 thanks 🙏

  • @thelife8836
    @thelife88363 жыл бұрын

    The best tutorial. Is single wheel update method essential?

  • @dwinkley

    @dwinkley

    3 жыл бұрын

    He stole the code from kzread.info/dash/bejne/nGqTta-dh8itdqw.html

  • @timhoutman6413
    @timhoutman64133 жыл бұрын

    5:35 love the way how you say motor torques. Thanks for the video man.

  • @RobertGatesC
    @RobertGatesC3 жыл бұрын

    Dude, you are a lifesaver. Thank you, brother. I was looking for a vid that would go step by step through the process, and if people want to check the coding under the hood so to speak, you have that too. For someone that doesn't know coding, and wants to put out a game, this is amazing info. And how you did it step by step. Love it. Would you also be able to make a vid of how to easily train any AI car to run a track, and with other AI cars? If so, that would be amazing. Thanks again, and a big thumbs up from me. :)

  • @FelineRaptor-gv4te

    @FelineRaptor-gv4te

    2 жыл бұрын

    As for ai cars, you can check out Unity's standard assets. there is something called car ai waypoint.

  • @zihagamers4073
    @zihagamers40733 жыл бұрын

    Thanks a lot! Buddy

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

    Super Helpful!!! By the way if you make the engine to powerful it the car will flip. I made a little script to fix that though. Script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Flip : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.V)) { transform.rotation = Quaternion.Euler(0, 0, 0); } } }

  • @nsb_tv5820
    @nsb_tv58202 жыл бұрын

    the only word is perfect for this video

  • @pewdapumpum5121
    @pewdapumpum51212 жыл бұрын

    Very good.. THNX BROOO

  • @nokia_n-gage
    @nokia_n-gage2 жыл бұрын

    Dude, you're the best!Hello from Russia)

  • @rajdeepdas86
    @rajdeepdas863 жыл бұрын

    Awesome hands-on tutorial. Can you please do a similar tutorial for bicycle?

  • @trunkmonkey5749

    @trunkmonkey5749

    2 жыл бұрын

    I'd just take away a set of wheel colliders and add a bike model. I think it'd be very similar to the car.

  • @kashifxahmed2087
    @kashifxahmed20872 жыл бұрын

    Thank you so much it worked for me i watched a lot of tutorial but didn't work but now because of u it worked....Thank you so much!!

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

    Such a genius

  • @wa-ir1br
    @wa-ir1br3 жыл бұрын

    広告から飛んできたけどまじでわかりやすい!

  • @officialtatex

    @officialtatex

    2 жыл бұрын

    true

  • @0kr4m
    @0kr4m2 жыл бұрын

    great tutorial! one question: is there a way to give a boost in speed? I can't even change speed values.

  • @bloggerblogger2410

    @bloggerblogger2410

    2 жыл бұрын

    yea i've the same question i need the car to accelerate quicker and go faster and changing the speed/motorForce didn't help at all .

  • @nikkuzmich5378
    @nikkuzmich53783 жыл бұрын

    Great tutorial! I did the same with my car, but I had one strange problem: my wheels do not rotate around themselves, they rotate in a circle with a certain radius... I solved this by creating empty objects in the same place as wheels, and used them as transforms. But I think this is not an ideal solution, as in a collision the wheels are raised... and not lowered.

  • @hdprodesignteam231

    @hdprodesignteam231

    2 жыл бұрын

    Hi Niaz. Check this links: Hope helps. kzread.info/dash/bejne/eIqqj8p-kqe3ccY.html kzread.info/dash/bejne/eaCV0cuTaJOxk7g.html Playable Demo : drive.google.com/file/d/1_JnQSfTP8E7EfKZhJVdClohhxBQ7cgei/view?usp=sharing Kindly waiting for your comments to improve it. Thanks.

  • @forgodsakejake

    @forgodsakejake

    2 жыл бұрын

    i had the exact same issue, was trying to find a solution for so long so thank you for this

  • @vincenthornak7469

    @vincenthornak7469

    2 жыл бұрын

    @@forgodsakejake I am still confused on how they got this working... I am having the exact same issue. Any tips?

  • @gglobensky

    @gglobensky

    2 жыл бұрын

    It's because the pivot point of the object is not in the center. Just parent the mesh onto a gameObject with the right pivot and move all the scripts to the empty parent you just created.

  • @nowledge8131
    @nowledge81313 жыл бұрын

    Thank you very much :)

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

    Thanks, it worked! But the rear wheels are rotated at Y180, please help

  • @mcnuffey8629
    @mcnuffey86297 ай бұрын

    Thank you!

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

    thanks for tutorial

  • @operationreddit1804
    @operationreddit18043 жыл бұрын

    great tutorial, exactly what I was looking for, there is only one problem that i'm facing. its input lag. when I put motorForce to 2000 for example, and when I try to break, there is a lag of about second or 2 before starting to break, and problem is amplified with higher numbers, at 5000 its about 4-5 seconds. does someone have a solution for this?

  • @hdprodesignteam231

    @hdprodesignteam231

    2 жыл бұрын

    Check this links: Hope helps. kzread.info/dash/bejne/eIqqj8p-kqe3ccY.html kzread.info/dash/bejne/eaCV0cuTaJOxk7g.html Playable Demo : drive.google.com/file/d/1_JnQSfTP8E7EfKZhJVdClohhxBQ7cgei/view?usp=sharing Kindly waiting for your comments to improve it. Thanks.

  • @EZ-GAZI
    @EZ-GAZI3 жыл бұрын

    GOOD VIDEO KEEP GOIN

  • @haikunHuanghk
    @haikunHuanghk2 жыл бұрын

    很好,没有一句是废话,看完就会了,感谢分享

  • @ZohaibAhmad-hf6zq
    @ZohaibAhmad-hf6zq Жыл бұрын

    Extraordinary!

  • @sinanarts
    @sinanarts2 жыл бұрын

    Hi, Can I use the same exact flow for a VR Car simulation.?

  • @lld8m828
    @lld8m8283 жыл бұрын

    Thank you

  • @kheenzii
    @kheenzii2 жыл бұрын

    amazing! :)

  • @kimjongun5739
    @kimjongun57392 жыл бұрын

    Does anyone know why my current break force in the inspector tab stays at 0 (whenever I change it just goes back to 0) when I start playing my game?

  • @bowl1858
    @bowl18582 жыл бұрын

    Good tutorial, one question. When I start moving my car, once it gets to a certain speed it starts jittering side to side really quickly and leans to the left. My wheels are all at the same y axis, and tinkering with the settings is doing nothing. How do i fix this????

  • @Rikko230392

    @Rikko230392

    2 жыл бұрын

    I have same problem

  • @Jimblesnitronbo

    @Jimblesnitronbo

    2 жыл бұрын

    I had the same problem too, but whenever I change the mass in the car's "Rigidbody" component, it fixes it! Hope this helps!

  • @ooblae3797
    @ooblae37972 жыл бұрын

    Does the car infinitely accelerate with this script? If so how can you cap the speed of the car?

  • @derickchan3638
    @derickchan36382 жыл бұрын

    when i try to turn left or right when its reach high speed how to make the car not flipping should i change the mass of the car and the wheels?

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

    can someone explain to me, what visual studio extensions used on this video ? especially for the auto methods, auto type and colorize ? thank you

  • @documentary6278
    @documentary62782 жыл бұрын

    thanks my bro

  • @HideOnDark
    @HideOnDark2 жыл бұрын

    Thank you. That's great but wheels spin when the car is stationary and when you go fast, the wheels rotate

  • @farukozturk7175
    @farukozturk71752 жыл бұрын

    this is crazy bro

  • @hdprodesignteam231

    @hdprodesignteam231

    2 жыл бұрын

    Hi Faruk, May be you also want see that. Intro: kzread.info/dash/bejne/pX9mtraif8XRabA.html Demo: drive.google.com/file/d/1YV9mxdCTPMBnnaZNlk8YJX9e06HYrU4K/view?usp=sharing Doc: docs.google.com/document/d/1b0_MDYscz7XrB1VZVjdV8UDEvLlWaMkm/edit?usp=sharing&ouid=109722518578274411105&rtpof=true&sd=true In case you need questions, do not hesitate. Thanks. Best Regards HD Pro Design Team

  • @nour3660
    @nour36603 жыл бұрын

    when i finally finished and wanted to add the script to the car it says can't add component, make sure that there is no compliers i checked the console and there was nothing but in the car's inspector it says, recalculate light active LOD bias is 2.0, distances are adjusted accordingly i hit the recalculate button but nothing happens any suggestions? edit: i didn't do the render pipeline thing in the fire of the video because i can't find it

  • @tonyhamilton7785
    @tonyhamilton77853 жыл бұрын

    This is hella advanced. All I need is to make the car turn left & right when moving

  • @saiyanpridezbudokitenkaich3444

    @saiyanpridezbudokitenkaich3444

    3 жыл бұрын

    Its not advanced if u understand c# but this guy speaks faster than 6000 MotorTorque

  • @BerzahMusic

    @BerzahMusic

    3 жыл бұрын

    lol

  • @bamers404

    @bamers404

    2 жыл бұрын

    Then a car game is not for you. Because it's all bout physics

  • @tonyhamilton7785

    @tonyhamilton7785

    2 жыл бұрын

    @@bamers404 Not really. I learned a lot over these months. Even the best programmers have to google how-to and error videos. Its all about following instructions to know how to do it in the future. I made a car game and got it working, but I scratched it for other ideas

  • @FelineRaptor-gv4te

    @FelineRaptor-gv4te

    2 жыл бұрын

    If you want it so simple without proper physics, then try this- using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyCarController : MonoBehaviour { public float maxSpeed = 30f; // Our maximum speed allowed. public float curSpeed; // Current Speed; public float applySpeed = 20f; // How much force to apply (Forward). public float brakeForce = -10f; // Breaks. public Rigidbody myRigid; // Our Rigidbody. public int turnAmount; void Start() { myRigid = GetComponent(); // Gets the players Rigidbody. } void FixedUpdate() { curSpeed = myRigid.velocity.z; if(curSpeed >= maxSpeed) { applySpeed = curSpeed; } if(Input.GetKey(KeyCode.UpArrow)) { //Apply Accelleration myRigid.AddRelativeForce(Vector3.forward * applySpeed); } if(Input.GetKey(KeyCode.DownArrow)) { //Apply BREAKS myRigid.AddRelativeForce(Vector3.back * brakeForce); } } void Update() { if(Input.GetKey(KeyCode.A)) { transform.Rotate(Vector3.up * -turnAmount * Time.deltaTime); } if(Input.GetKey(KeyCode.D)) { transform.Rotate(Vector3.up * turnAmount * Time.deltaTime); } } This wasactually a script for flying a plane in a post in Unity Answers but I tweaked the script to make it a car controller. Just remember to add a rigidbody [with mass 1] to your car GameObject and a box collider with a suitable size and position. Any problem wiht the script, ask me.

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

    dude everything is nice and all but how do i add lerp to the Turing of wheel from left to right because it just snaps which i don't like so any idea on how to

  • @IGNACY-fp8zo
    @IGNACY-fp8zo2 жыл бұрын

    The wheels just instantly fly off and sink below the ground for me and for some reason the breaks seem to accelerate the flying wheels

  • @kavipriyank8298

    @kavipriyank8298

    2 жыл бұрын

    Totally the same here! For me, the wheels seem to detach from the car's body in a weird manner and fly away. Its transform keeps changing constantly, while the car's body just falls down on land.

  • @vmancool
    @vmancool3 жыл бұрын

    Any ideas why i would have black wheels?

  • @ninjacodertech
    @ninjacodertech10 ай бұрын

    thanks!

  • @nbgtube468
    @nbgtube4682 жыл бұрын

    I’m having problems where the wheel colliders start to push away from the vehicle making it float, does anyone know how to fix?

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

    @Hawk Game Dev Hey sorry for asking but I am having a problem... When I am clicking the play button. The left side of my car sinks in the ground while other stays normal (like a flat tire for left side). How can i fix? If u know ofcourse

  • @axer1015
    @axer10153 жыл бұрын

    Man only problem is YOU GO TOO FAST! GO SLOWER!

  • @1agent3LT

    @1agent3LT

    3 жыл бұрын

    yea

  • @jorande1e

    @jorande1e

    2 жыл бұрын

    The pause button exists

  • @WajiD_xD

    @WajiD_xD

    2 жыл бұрын

    Or just leave the world

  • @Rodehaas

    @Rodehaas

    Жыл бұрын

    0.5x speed?

  • @ayafathi3157
    @ayafathi31574 ай бұрын

    thanks so much

  • @josefyang
    @josefyang3 жыл бұрын

    How do you increase thee speed of the car?

  • @TheCoolcomplex
    @TheCoolcomplex2 жыл бұрын

    why are the rear wheels being updated if the parameters of rear wheel colliders never change? from my understanding, the front wheel colliders move according to the torque that is being applied, and the wheel transforms have to be updated to match the wheel collider positions and rotations, but from the code itself, the rear wheel colliders do not move since the torque is only applied to the front wheels in the code, so how do the rearwheel colliders move?

  • @miguelpereira4645

    @miguelpereira4645

    Жыл бұрын

    The physics system automatically move them when the car moves because they are rolling in the ground

  • @joseenriquejoson1994
    @joseenriquejoson19942 жыл бұрын

    Sir, help me! I followed your instructions but when my game began to play, the car's steering angle is resetted to zero. How do I make sure that the steering angle with remain the same

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

    Tahnks i need to understand the whell collider thing

  • @NONSTOP-or5mu
    @NONSTOP-or5mu Жыл бұрын

    Great video! But I can't seem to fix the problem that my maximum steer angle is 1 to -1 and my current break force doesn't change when breaking at all. Does anyone have the same problem or knows how to fix it?

  • @megozcreed5196
    @megozcreed51963 жыл бұрын

    if I want the car to apply brakes as soon as I release any of the W S or Up Down buttons , what should I do

  • @Randomiz8orinator

    @Randomiz8orinator

    3 жыл бұрын

    try reading the input.GetKeyUp method

  • @megozcreed5196

    @megozcreed5196

    3 жыл бұрын

    @@Randomiz8orinator well i knew about them , I was meaning how to stop the car momentum , what code to put in the get key up func. I tried motor torque =0 Brake torque = Mathf.infinity But it still didn't stop as soon as key up So had to play with the rigidbody velocity for it to work.

  • @thaddeusnoffsinger2410

    @thaddeusnoffsinger2410

    3 жыл бұрын

    Did you figure this out? Having the same question.

  • @nodel1342
    @nodel13422 жыл бұрын

    why are we using SerializeField instead of the normal class. I just want to know

  • @untemi0
    @untemi03 жыл бұрын

    THANK BRO

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

    WheelCollider's GetWorldPose is messing up WheelTransform's position. It's pushing the wheel away for certain distance. What might cause it?

  • @halivudestevez2
    @halivudestevez22 жыл бұрын

    I wonder why to wheel models and colliders are separated in every example?

Келесі