Simple Car Controller in Unity Tutorial

  Рет қаралды 330,766

GameDevChef

GameDevChef

Күн бұрын

Пікірлер: 697
@Massive-3D
@Massive-3D 4 жыл бұрын
I was so afraid to scroll down and see "video upload date: 5 years ago" Subscribed!
@uniquelyrics2331
@uniquelyrics2331 4 жыл бұрын
lol
@matheusmartins3177
@matheusmartins3177 3 жыл бұрын
me too LOL
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 3 жыл бұрын
i HATE that.
@federic.d.souza74
@federic.d.souza74 3 жыл бұрын
lol
@3bomb
@3bomb 3 жыл бұрын
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:)
@T0MM0-Lds
@T0MM0-Lds 3 жыл бұрын
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.
@RandomNovaGames
@RandomNovaGames 4 жыл бұрын
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
@rubenopenworld8405
@rubenopenworld8405 4 жыл бұрын
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 3 жыл бұрын
@@monkeyrobotsinc.9875 you have to be kidding, if youre somewhat experienced you should be able to catch up with this easily
@carolineyonatan216
@carolineyonatan216 4 жыл бұрын
Lol i see this ad while watching dani
@swastikmishra8822
@swastikmishra8822 4 жыл бұрын
Same bro
@vvixell1
@vvixell1 4 жыл бұрын
same
@neongreggyyt1115
@neongreggyyt1115 4 жыл бұрын
Same
@suanzalal
@suanzalal 4 жыл бұрын
Ah. I see you're a Boner aswell.
@youdaily7113
@youdaily7113 4 жыл бұрын
Ssssssnanananana same
@axer1015
@axer1015 3 жыл бұрын
Man only problem is YOU GO TOO FAST! GO SLOWER!
@1agent3LT
@1agent3LT 3 жыл бұрын
yea
@jorande1e
@jorande1e 3 жыл бұрын
The pause button exists
@Fellamemer
@Fellamemer 2 жыл бұрын
Or just leave the world
@Rodehaas
@Rodehaas 2 жыл бұрын
0.5x speed?
@luiss.2005
@luiss.2005 3 жыл бұрын
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 3 жыл бұрын
What did you use in HandleRotation? There is no SmoothDamp
@luiss.3866
@luiss.3866 Жыл бұрын
Are we brothers?
@TheEdugato100
@TheEdugato100 3 жыл бұрын
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
@lawrenceredmacher4382
@lawrenceredmacher4382 2 жыл бұрын
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
@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!!
@IGNACY-fp8zo
@IGNACY-fp8zo 2 жыл бұрын
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.
@markpolak8622
@markpolak8622 4 жыл бұрын
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 4 жыл бұрын
@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 3 жыл бұрын
@@jacobpatron8387 thankyou soooo much dude
@bamers404
@bamers404 3 жыл бұрын
@@jacobpatron8387 thanks 🙏
@nikkuzmich5378
@nikkuzmich5378 3 жыл бұрын
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 3 жыл бұрын
Hi Niaz. Check this links: Hope helps. kzbin.info/www/bejne/fIfZXpt7l6mEd8U kzbin.info/www/bejne/fZ3EoJyQbZV-mbc 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.
@lostsoop
@lostsoop 3 жыл бұрын
How can i change the speed / acceleration of the car?
@matymare
@matymare 3 жыл бұрын
Change motor force amount
@lostsoop
@lostsoop 3 жыл бұрын
@@matymare it doesnt help ig but thank you anyways
@barebones.
@barebones. 3 жыл бұрын
if you want to make it slower then you can increase drag ( 1 - 3 will probably be as high as you can go ), but im not sure how to make it faster.
@lostsoop
@lostsoop 3 жыл бұрын
@@barebones. i think the car falls over when i increase the drag
@Max-kb6ui
@Max-kb6ui 3 жыл бұрын
@@lostsoop Same problem
@ElectronGOD
@ElectronGOD 4 жыл бұрын
Once the BrakeTorque is applied, car does not move again when I release the break. Plz help.
@GameDevChef
@GameDevChef 4 жыл бұрын
You can try to remove the isBreaking check on line 45 and make sure that the brakeTorque is set to 0 when spacebar is not pressed.
@boinas
@boinas 4 жыл бұрын
you can try to do this: private void HandleMotor() { if (isBreaking) breakForce = 3000; else breakForce = 0; frontLeftWheelCollider.motorTorque = verticalInput * motorForce; frontRightWheelCollider.motorTorque = verticalInput * motorForce; currentBreakForce = isBreaking ? breakForce : 0f; // you don't need this part because of the if and else you do upper ApplyBreaking(); } ApplyBreaking () { // right there i don't put all wheel colliders! the type of wheel colliders you put here is according to the traction you want to put in the car! // I put for a RWD car (rear-wheel drive)! the video is made for AWD car (all-wheels drive)! // It's to everyone's taste! ;D rearLeftWheelCollider.brakeTorque = currentBreakForce; rearRightWheelCollider.brakeTorque = currentBreakForce; } This method works but if you want a clean and more professional code try to do the wheels colliders with lists! and you can call the wheels with a simple foreach! And carefull because "break" writes "brake"! it's normal this type of errors while programming! especially if you're not english! i can't talk about this because even I do this type of errors! but if you want a correct code try to change "break" and "breaking" to "brake" and "braking"! But sure it was a good tutorial! Congratulations GameDevChef! Keep like that! One more like! 👍 =D
@GameDevChef
@GameDevChef 4 жыл бұрын
I found the problem. Remove the isBreaking check on line 52 in Car Controler script. That should make it work
@shivamchhapola5245
@shivamchhapola5245 4 жыл бұрын
@@GameDevChef can you explain why it works without the check
@counterpointerz-rocketleag2038
@counterpointerz-rocketleag2038 3 жыл бұрын
thanks, you guys will definitely need to do some research about the different things he did, but coding is all about teaching yourself
@elitebooger8208
@elitebooger8208 4 жыл бұрын
So my car just flys threw the air and I changed the weight on the wheels and body.
@musicland5786
@musicland5786 4 жыл бұрын
Just add a component (rigid body)
@diliupg
@diliupg 3 жыл бұрын
congratulations on the flying car! :-D
@theplaymakerno1
@theplaymakerno1 3 жыл бұрын
Got please you mate. This script is better than most of the bloated crap we find on the asset store.
@joshuastoddard3556
@joshuastoddard3556 2 жыл бұрын
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); } } }
@walney2008
@walney2008 4 жыл бұрын
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?
@timhoutman6413
@timhoutman6413 3 жыл бұрын
5:35 love the way how you say motor torques. Thanks for the video man.
@tonyhamilton7785
@tonyhamilton7785 3 жыл бұрын
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 3 жыл бұрын
Then a car game is not for you. Because it's all bout physics
@tonyhamilton7785
@tonyhamilton7785 3 жыл бұрын
@@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 3 жыл бұрын
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.
@bowl1858
@bowl1858 3 жыл бұрын
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 3 жыл бұрын
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!
@MphasieMusic
@MphasieMusic 3 жыл бұрын
OMG THANK YOU! You saved my project
@Vetrillum
@Vetrillum 2 жыл бұрын
Thanks, it worked! But the rear wheels are rotated at Y180, please help
@ghostawader9228
@ghostawader9228 2 жыл бұрын
Sorry I'm totally new to programming but why doesnt the Input.GetAxis and the Input.GetKey(Keycode.....) change color when I write it down on C# the exact same way he did it at 4:01. I noticed it happens to more rows aswell
@ghostawader9228
@ghostawader9228 2 жыл бұрын
It even gives me a warning about it at the bottom in a red text
@usman4854
@usman4854 4 жыл бұрын
2:04 sir simple is mesh collider because box colliders used in building and etc things
@aarushsharma9764
@aarushsharma9764 4 жыл бұрын
How I control this
@usman4854
@usman4854 4 жыл бұрын
@@aarushsharma9764 correct C# coding
@clement2814
@clement2814 2 жыл бұрын
Thank you so much. It's fast and efficient as needed.
@operationreddit1804
@operationreddit1804 3 жыл бұрын
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 3 жыл бұрын
Check this links: Hope helps. kzbin.info/www/bejne/fIfZXpt7l6mEd8U kzbin.info/www/bejne/fZ3EoJyQbZV-mbc Playable Demo : drive.google.com/file/d/1_JnQSfTP8E7EfKZhJVdClohhxBQ7cgei/view?usp=sharing Kindly waiting for your comments to improve it. Thanks.
@FC12CGaming
@FC12CGaming 4 жыл бұрын
Omg thanks so much, i'm literally speechless that it actually works!!!!
@idkidc1885
@idkidc1885 4 жыл бұрын
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 4 жыл бұрын
@@idkidc1885 no im using 2019.4
@FC12CGaming
@FC12CGaming 4 жыл бұрын
@@idkidc1885 but it should work on the new unity
@idkidc1885
@idkidc1885 4 жыл бұрын
@@FC12CGaming ok ty if it doesnot work on the new ill try that version
@FC12CGaming
@FC12CGaming 4 жыл бұрын
@@idkidc1885 k
@Nexus-fi1hb
@Nexus-fi1hb 4 жыл бұрын
The wheel colliders of my car just detatch and fly into the air and pressing wasd doesen't change anything, pls help
@m0ch1_6
@m0ch1_6 4 жыл бұрын
Hey Nexus, to fix your problem you should ensure that wheel collider and wheel mesh are not on the same game object or child
@Nexus-fi1hb
@Nexus-fi1hb 4 жыл бұрын
@@m0ch1_6 thx, I've already fixed that problem, but now I can't get my car to get faster, no matter what motor force I set. It just keeps driving at the same speed.
@AugGust
@AugGust 4 жыл бұрын
@@Nexus-fi1hb U mean for acceleration? If turn the camera to the side u can see in the sample project, the tyres do not have enough grip and the tyres just slip
@lukascampbell5881
@lukascampbell5881 4 жыл бұрын
@@AugGust hey, do you know what i should do if only my front two wheels are rotating? (& turning)
@AugGust
@AugGust 4 жыл бұрын
@@lukascampbell5881 The setup for the front and back wheels should be identical? Just go through and make sure you didn't miss anything
@Theferrariguy
@Theferrariguy 4 жыл бұрын
Whenever I play the game, The car's motor and brake force change to different setting sand the car goes really slowly please help
@harshvardhanmisal2255
@harshvardhanmisal2255 4 жыл бұрын
Change it in inspector window click on object which has script and then change the values
@Croccolucho
@Croccolucho 4 жыл бұрын
Got the same problem, idk what to do
@Theferrariguy
@Theferrariguy 4 жыл бұрын
@@Croccolucho I ended up using vehicle physics pro asset it's very useful I'd recommend it
@mythicaldriftz3357
@mythicaldriftz3357 3 жыл бұрын
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
@blissweb
@blissweb 3 жыл бұрын
I came here to see how to fix the purple car syndrome and you did that in the first minute. :-) Yay.
@Twiney_
@Twiney_ 2 жыл бұрын
This is my first time coding and it works great thanks dude!
@0kr4m
@0kr4m 2 жыл бұрын
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 .
@edmashokmusic1692
@edmashokmusic1692 Жыл бұрын
For all those looking for car not moving after applying brakes. read the video description
@drewvananne1796
@drewvananne1796 3 жыл бұрын
Exactly what I was looking for, great tutorial!
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 3 жыл бұрын
really cool that this worked, thanks, but i just used cinemachine for the follow camera.
@FelineRaptor-gv4te
@FelineRaptor-gv4te 3 жыл бұрын
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].
@DrSwagGaming
@DrSwagGaming 2 жыл бұрын
@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
@MoonBro
@MoonBro Жыл бұрын
I used this tutorial and physics are working find but for some reason my car just rolls back at 8:13. Oh and for people that are having bouncy wheels and crap reset your transforms on the rotation on your wheels to 0 in blender or with some unity script should solve your problem. (nvm i fixed it just set the motor force to negative)
@nbgtube468
@nbgtube468 2 жыл бұрын
I’m having problems where the wheel colliders start to push away from the vehicle making it float, does anyone know how to fix?
@ImScorpy
@ImScorpy 2 жыл бұрын
Note to people trying to make a Vehicle controller: DO NOT use Time.deltaTime on the motorTorque code
@kimjongun5739
@kimjongun5739 2 жыл бұрын
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?
@infinit_y7000
@infinit_y7000 Жыл бұрын
The script wouldn't work it tell me "the reference script on this Behaviour (Game Object 'Car' ) is missing"
@rustyrishii
@rustyrishii 3 жыл бұрын
Breaking is not working for me
@SakthivelNadar
@SakthivelNadar 4 жыл бұрын
This is sooo simple it reminds me physics and maths class not that much i ever attended to maths
@TheCoolcomplex
@TheCoolcomplex 3 жыл бұрын
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 2 жыл бұрын
The physics system automatically move them when the car moves because they are rolling in the ground
@erfanroghani
@erfanroghani 2 жыл бұрын
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?
@TFG287
@TFG287 3 жыл бұрын
Assets\sCRIPTS\CarControol.cs(72,1): error CS1022: Type or namespace definition, or end-of-file expected :I need help
@jvstAsYouAre
@jvstAsYouAre 3 жыл бұрын
I have seen a couple of comments asking how it could be possible for the wheels to be rotated 90 degrees when you start the game but nobody has been able to answer the question. PLEASE HELP!
@maximizer174
@maximizer174 3 жыл бұрын
yeah, me 2...pls help
@a7medabdalhadi780
@a7medabdalhadi780 3 жыл бұрын
I think u made ur own car then imported it into unity I faced this problem also and it is easy to fix, u have to change some details in the script -First go updatesinglewheel method and enter new Quaternion called it "Rightrotation" or any name u want to -next write down this line: Rightrotation=new Quaternion (rot.X, rot.y-1,rot.z,rot.w); //this line should be written after Wheelcollider.getworldpose... etc// -Then change wheeltransform.rotation into: wheeltransform.rotation= Rightrotation; I wish this could help u :)
@browneburbs5377
@browneburbs5377 Жыл бұрын
I have some problematic issues. While I am using a different car model, I don't think it should be any different than what this model provides, but regardless: I've followed the tutorial very well, but I've ran into two problems. When I add a Wheel Collider, it doesn't show up at all during the editing, unless I make a rigidbody component. But once everything was set up and handled, the car either bounces and flies in all sorts of directions that's not wanted, the wheels fall through the plane and into the abyss, or all the wheels snap to position 0, 0, 0. It's very infuriating and I'd love to get this fixed!
@RavishingPimp
@RavishingPimp Жыл бұрын
(If anyone needs it. I did make some differences (Like capital letters on some stuff, but that's all) using System.Collections; using System.Collections.Generic; using UnityEngine; public class CarController : MonoBehaviour { // Rename the terms used in the Unity physics engine private const string HORIZONTAL = "Horizontal"; private const string VERTICAL= "Vertical"; private float HorizonalInput; private float VerticalInput; private float currentbreakForce; private float steerAngle; // Choose whether to break or not private bool IsBreaking; [SerializeField] private float motorForce; [SerializeField] private float breakForce; [SerializeField] private float maxSteerAngle; // SerializeField is because we don't want other scripts to access it, but we do in the inspector [SerializeField] private WheelCollider FrontLeftWheelCollider; [SerializeField] private WheelCollider FrontRightWheelCollider; [SerializeField] private WheelCollider RearLeftWheelCollider; [SerializeField] private WheelCollider RearRightWheelCollider; [SerializeField] private Transform RearRightWheelTransform; [SerializeField] private Transform RearLeftWheelTransform; [SerializeField] private Transform FrontRightWheelTransform; [SerializeField] private Transform FrontLeftWheelTransform; // We use "FixedUpdate" because we need to use the Unity physics engine private void FixedUpdate() { GetInput(); HandleMotor(); HandleSteering(); UpdateWheel(); } private void GetInput() { HorizonalInput = Input.GetAxis(HORIZONTAL); VerticalInput = Input.GetAxis(VERTICAL); IsBreaking = Input.GetKey(KeyCode.Space); } private void HandleMotor() { FrontLeftWheelCollider.motorTorque = VerticalInput * motorForce; FrontRightWheelCollider.motorTorque = VerticalInput * motorForce; currentbreakForce = IsBreaking ? breakForce : 0f; if (IsBreaking) { ApplyBreaking(); } } private void ApplyBreaking() { FrontRightWheelCollider.brakeTorque = currentbreakForce; FrontLeftWheelCollider.brakeTorque = currentbreakForce; RearRightWheelCollider.brakeTorque = currentbreakForce; RearLeftWheelCollider.brakeTorque = currentbreakForce; } private void HandleSteering() { steerAngle = maxSteerAngle * HorizonalInput; FrontLeftWheelCollider.steerAngle = steerAngle; FrontRightWheelCollider.steerAngle = steerAngle; } private void UpdateWheel() { UpdateSingleWheel(FrontLeftWheelCollider, FrontLeftWheelTransform); UpdateSingleWheel(FrontRightWheelCollider, FrontRightWheelTransform); UpdateSingleWheel(RearRightWheelCollider, RearRightWheelTransform); UpdateSingleWheel(RearLeftWheelCollider, RearLeftWheelTransform); } private void UpdateSingleWheel(WheelCollider WheelCollider, Transform wheelTransform) { Vector3 pos; Quaternion rot; WheelCollider.GetWorldPose(out pos, out rot); wheelTransform.rotation = rot; wheelTransform.position = pos; } }
@HideOnDark
@HideOnDark 2 жыл бұрын
Thank you. That's great but wheels spin when the car is stationary and when you go fast, the wheels rotate
@thelife8836
@thelife8836 4 жыл бұрын
The best tutorial. Is single wheel update method essential?
@dwinkley
@dwinkley 4 жыл бұрын
He stole the code from kzbin.info/www/bejne/oGfChICajMp6fKs
@walney2008
@walney2008 4 жыл бұрын
I put the wheel configurations as in the video, but even putting a mass of 50000 the car will still be lifting, what can it be?
@leonamferreira8053
@leonamferreira8053 3 жыл бұрын
try changing the suspension spring to 90000 and damper to 9000 on the wheel collider. Remember to change it for every wheel collider on each wheel.
@virxest
@virxest 2 жыл бұрын
Even these tutorials are one big headache. When I finally get to the "Asset Store" and downloaded this package, I press "Open in Unity" and nothing happens. I already need a tutorial for this tutorial. I could only download but how do I "Import"?
@ZAYMANGAMESTUDIO
@ZAYMANGAMESTUDIO 2 жыл бұрын
Hi, my issue is that I don’t want to use only pc to brake the car, but also my joystick
@megozcreed5196
@megozcreed5196 4 жыл бұрын
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 4 жыл бұрын
try reading the input.GetKeyUp method
@megozcreed5196
@megozcreed5196 4 жыл бұрын
@@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.
@halivudestevez2
@halivudestevez2 2 жыл бұрын
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)
@bithigh8301
@bithigh8301 2 жыл бұрын
It works pretty good. Thank you!
@RobertGatesC
@RobertGatesC 4 жыл бұрын
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 3 жыл бұрын
As for ai cars, you can check out Unity's standard assets. there is something called car ai waypoint.
@eleanordare9350
@eleanordare9350 3 жыл бұрын
very clear and solved all my problems, thanks so much :-)
@salmansaleem2191
@salmansaleem2191 2 жыл бұрын
bro, the car isn't moving with the arrow and WSAD keys, the wheels turn but the car doesn't move forward or backwards please help thank you
@wingy4387
@wingy4387 3 жыл бұрын
Followed exactly as you did, but sadly my car still seems to spin out so easily when turning, I've played with changing values and have also moved the wheel colliders slightly, which helped a bit but it still can't handle driving around a track at speed, what can I do to make it better?
@hdprodesignteam231
@hdprodesignteam231 3 жыл бұрын
Hey Wingy, Here some links for the HD Car Controller V 3.5. kzbin.info/www/bejne/fIfZXpt7l6mEd8U kzbin.info/www/bejne/fZ3EoJyQbZV-mbc Playable Demo : drive.google.com/file/d/1_JnQSfTP8E7EfKZhJVdClohhxBQ7cgei/view?usp=sharing Kindly waiting for your comments to improve it. Thanks. Best Regards HD Pro Design Team
@simplygamedeveloper7859
@simplygamedeveloper7859 2 жыл бұрын
Change the value of suspension to 1.
@roostydoo2
@roostydoo2 3 жыл бұрын
Will it still work if you don't use lwrp project ?? EDIT: I'm using 3d with extras
@punit11super
@punit11super 3 жыл бұрын
Yes it will
@luxxstar
@luxxstar 3 жыл бұрын
Hello Can anyone help me? If I want to put body into the empty object "Visual", I get a message that I cannot do this in any prefabs
@CHKNSkratch
@CHKNSkratch 3 жыл бұрын
you're supposed to unpack the prefab completely
@rajdeepdas86
@rajdeepdas86 3 жыл бұрын
Awesome hands-on tutorial. Can you please do a similar tutorial for bicycle?
@trunkmonkey5749
@trunkmonkey5749 3 жыл бұрын
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.
@edmashokmusic1692
@edmashokmusic1692 Жыл бұрын
my car not moving in an inclined plane about 15° also
@victorfiy9844
@victorfiy9844 2 жыл бұрын
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
@Thoonder
@Thoonder 4 жыл бұрын
im having a problem. if i stop moving after driving a bit. i cannot move at all anymore idk how to fix
@favour5442
@favour5442 4 жыл бұрын
Check the discription, the solution is there
@gamedev_navneet
@gamedev_navneet 3 жыл бұрын
I like your discipline while coding.
@HitesH3D
@HitesH3D 3 жыл бұрын
I made the car with a fully functional car controller. it was working fine but when I use the same script and method on the new car mess it's not working. well are rotating but the car is not moving. any solution.
@vinnypantano6858
@vinnypantano6858 2 ай бұрын
IDK why but my turning angle only goes to 1% even though I have the max set to 50
@sebasA
@sebasA 2 жыл бұрын
Thanks, how can I do to stop the car slowly while Im not pressing up key with just the friction? Actually the car never stops, just with break.
@iRuR
@iRuR 2 жыл бұрын
W is for throttle, S is for brake, Space is for handbrake i think
@Dybala-jv7pg
@Dybala-jv7pg 2 жыл бұрын
like What are the basics you need to learn to produce a , or setup it. Also I need to learn how to add soft notes to a .
@FelineRaptor-gv4te
@FelineRaptor-gv4te 3 жыл бұрын
I have a problem with slowing down when not accelerating. The car doesn't do that. I want the car to stop after a while if the car doesn't recieve input while accelerating forward or backward. I tried using the max friction physics material for the plane in the environment, but it doesn't work. Someone please help.
@luanayres9418
@luanayres9418 2 жыл бұрын
I'm using a model car from the polygon city pack and I get a error: "Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5". I noticed too that the wheels already have a sphere collider, but i don't know how to adapt it to the script. I'm new to unity, please someone help.
@anonymousa7030
@anonymousa7030 3 жыл бұрын
THANK YOUU!! it is very simple and helpful
@peterbutterfield1153
@peterbutterfield1153 4 жыл бұрын
So the moving / driving is working fine i changed the motor a bit to suite my little game but the breaking just is not working iv tried removing the "isbreaking check" on the line 52 like you said to another person in the comments and i tried what another person said to that reply and neither worked well the original worked kinda where it breaks but then stuck with the break i also tried a few solutions i thought of but non of them worked mainly one that checks if break force is 3000 then check if space is being clicked make the motor torque to the breaking force that is required to stop the car from moving. Any help would be great
@marcosbenedico7304
@marcosbenedico7304 4 жыл бұрын
Same problem
@NewEraGamersOP
@NewEraGamersOP 2 жыл бұрын
Any solution you got ?
@guyoguy
@guyoguy 3 жыл бұрын
uhh when i do it the car glitches out and then only 1 wheel is actually turning what do i do aaaa
@iamakshobhyashukla
@iamakshobhyashukla Жыл бұрын
my car is moving, but, extremely extremely slow, even increasing the MotorForce doesn't work. Any idea why is this happening? Also, can anyone explain how do the arrow keys or WASD keys directly work in this case? It was never specified which key would be used for motion.
@RTZZZZZZXD
@RTZZZZZZXD 7 ай бұрын
how can i download and open the project, when i try to open it it shows nothing :(((
@julioaviles8125
@julioaviles8125 Жыл бұрын
what did you press on 5:43 to change only the 2 you needed
@1minutessvideo
@1minutessvideo 3 жыл бұрын
i want reset car posetion when car flipped what can i do
@BuoyEngine
@BuoyEngine 4 жыл бұрын
Big thank you !! this is so useful video.
@arpitkhatana3675
@arpitkhatana3675 4 жыл бұрын
Bro my car is rotating and flying can u help me.
@farruholimov8281
@farruholimov8281 2 жыл бұрын
WheelCollider's GetWorldPose is messing up WheelTransform's position. It's pushing the wheel away for certain distance. What might cause it?
@elicopter_go_brr
@elicopter_go_brr 4 жыл бұрын
so remember...this tutorial is VERY SIMPLE!
@francek3892
@francek3892 4 жыл бұрын
Unity doesnt support rigidbody, we need a new tutorial lol
@ripjawsproxy
@ripjawsproxy 3 жыл бұрын
I did all that he did, and fixed that one bug, but pressing the wasd or arrow keys does nothing. I require assistance on this issue. Also, I'm running 2019.4 version of unity.
@ItsKevin183
@ItsKevin183 2 жыл бұрын
How do I speed up the car/make it go fast immediately. (no slow start)
@halivudestevez2
@halivudestevez2 2 жыл бұрын
I wonder why to wheel models and colliders are separated in every example?
@Agenayt
@Agenayt 3 жыл бұрын
Your github download doesn't match the code you did in the video??? Downloaded code doesn't work, come on fix
@laetitialeduc9215
@laetitialeduc9215 Жыл бұрын
Hello i am almost done but i have issues with the begining with the [SerializedField] i had to make a public void SerializedField() To get it selected underneath but still it doent light up the wheel colliders and i work with the 2022 version
@laetitialeduc9215
@laetitialeduc9215 Жыл бұрын
Just started coding this week by myself i am learning thru differents tutorial and researches on the interner i made the vehicule myself on unity but stil have wheelcolliders on the vehicule
4 жыл бұрын
Thank you for making it simple
@KalebShewangizaw-b7i
@KalebShewangizaw-b7i Жыл бұрын
Please send us the c# code in pdf
@theplaymakerno1
@theplaymakerno1 3 жыл бұрын
The upgrading of the materials did not work for me.
@steveivanka
@steveivanka 3 жыл бұрын
theres something wrong in the code, my car doesnt move when i press the button. just moving aside by it self. and rear tires disappear
@muhdasyraf9928
@muhdasyraf9928 3 жыл бұрын
Hi! I got a problem when using your code... it seems that my car dint stop accelerate after i press forward...any idea to fix it??
@sinanarts
@sinanarts 2 жыл бұрын
Hi, Can I use the same exact flow for a VR Car simulation.?
Basic Car Movement in Unity
16:04
b3agz
Рет қаралды 105 М.
Simple Car Controller in Unity (Copy Script)
4:22
Sigma's United
Рет қаралды 123 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
Simple Car AI Driver in Unity!
13:17
Code Monkey
Рет қаралды 68 М.
How I Would Start Game Development (If I Started Over)
16:59
Thomas Brush
Рет қаралды 150 М.
Making Custom Car Physics in Unity (for Very Very Valet)
22:48
Toyful Games
Рет қаралды 139 М.
How to Create Road Tracks Using Road Architect in Unity
14:58
Arcade Style Car Controller || Unity Tutorial
21:20
SpawnCampGames
Рет қаралды 94 М.
I Made a Racing Game with No Experience
19:26
Hazardous
Рет қаралды 1,1 МЛН
Unity's NEW input system in 13 minutes
13:02
BiteMe Games
Рет қаралды 32 М.
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,3 МЛН