Amazing work! Im working on a car drift game 2 years now, but everytime is good to re-review the code of the car controller because is always something to perform!
Great work! I'm completely new to Unity and was able to follow your tutorial pretty well. Other than the webcam blocking the script, job well done. You've earned my subscription. :)
Thanks man. I am currently a university student in Turkey. I am studying Computer Programming. I had to make a game and it was going to be a car-based game. Luckily I came across your videos. It helped me a lot, thank you again. Greetings from Turkey to everyone.
This is one of the best Car Controller tutorials out there. Really Appreciate it. I also wondered how the vehicle damage system worked and how to implement it. +1 subscriber
Dude I've been looking for a car controller tutorial for a while now, after finding yours I have been so happy! Thanks for the great tutorial! +1 Subscriber!!
I get "error CS0246: The type or namespace name 'Mybutton' could not be found (are you missing a using directive or an assembly reference?)" why is that?
I have a problem with my car. I am using another car model but I did all the code correctly, but the car doesn't move as fluid in the video, and if go at a high speed, I can barely turn causing me to crash. How do I fix this?
Thanks for your tut bro! One problem, I noticed when you moving forward direction and use -1 input of vertical axis it's working fine. But whae you 're moving back and trying to go forward it's not used brake at all. I fixed it with DotProdunt of two vectors: movingDirection = Vector3.Dot(transform.forward, rb.velocity); if (movingDirection < -0.5f && gasInput > 0) { brakeInput = Mathf.Abs(gasInput); } else if (movingDirection > 0.5f && gasInput < 0) { brakeInput = Mathf.Abs(gasInput); } else { brakeInput = 0; }
Thanks for the tip man, I'll update the GitHub script to reflect the change. I found it a bit too complicated to mention it on this already long video.
Thanks for tutorial brother...it helps me a lot❣️ Can you make a video on race track like how car behave when hits race track walls or side barrier , and other obstacles And what kind of , a developer can face problems while making a racing game
I have a problem. 29:55 After following your steps and when I gave brake power value as 5000 then my car doesn't move. Brakes are applied automatically... can anyone help me
It should take jumps well as long as you set up the suspension aspect of the wheel colliders correctly. The com is determined by the rigidbody and the colliders. You can change that on the rigidbody. Also I don't have any forces pushing down on the vehicle
Hi, I have a problem. My car can move up, down, left and right, but my wheels doing some wierd things. They are like rotating around the car not rolling. It does like big circles around the car. Can you help me?
It's probably because the pivot point of the wheel is in the center of the vehicle. Try creating an empty game object, put it in place of the wheel and set the wheel mesh as a child of it.
@@nanousis Hi, it didnt work but I created cylinder and rotated it. It looked like it solved the problem but there is another one. Now it rolls up and down and not sideways. Do you think u can help me?
So I had added an Enter/Exit script onto my car and it works fine other than when i get out, my car continues to drive. Do you by chance know why or how to fix that issue? I know it isn't completely relevant to this video but of all the car controller tutorials I've watched, you are the best so I thought I'd ask if you knew how to handle my situation.
I have a probem. When the gasInput is 0, the car continues accelerating and I am not sure how to stop this (such that when the gasInput is 0 the car is neither decelerating or accelerating but just remains at the current speed and will decrease over time due to drag, friction, etc
@@nanousis Thanks for the advice but I realised that the problem was in the fact that motorPower was set to a really big value of 10000, so I reduced it to 1500. 🎉
Can i edit the drifting value i mean for example i want to build a rally game so all rally game have different cars i want to make some car drift less than other or even some of them cannot drift can i do that with this video?
Hello i imported the assets folder in the project but all of the shader is pink (Hidden/InternalErrorShader), is there any fix ? Edit: i managed to fix it by changing all of the Hidden/InternalErrorShader to Standard, it restored the materials to original form. Edit: the ground texture remain broken (only white color) but the car and smoke texture is fixed Edit: changing the ground texture albedo to grey instead of white fixes it , no longer broken
Hi, I have a problem, the wheel meshes do not update, I have checked the code and nothing seems to be missing, so if someone could help me I would apreciate it
Bro just change the wheel damping rate to 1, suspension distance to 0.1, spring to 70000, damper to 7000, and target position to 0.8 in wheel collider's property.
@@NitinKr7 hey, I have gotten a pretty bad solution, but for the moment, it is working pretty well, it consist on making another script only with the part of the script that manages the wheel update, idk if I have explained myself, but I have that helps you, and if you have any doubt you can ask me
It is possible that the normals of the wheels are wrong, create a new game object (maybe use a cube to see how it rotates) and use it as a parent for the wheels so that the new object rotates the wheel.
I would suggest you just import the asset folder instead. If that doesn't work go onto the new videos which is the improved version of that video file.
@@nanousis it would be great, because on youtube, i have never seen a video which explains wheel collider in detail and many of developers like me is facing this issue.
You can decrease the rear asymptote and extremum friction to make it more prone to oversteer. Other than that by setting the center of mass better and choosing correct values for springs should fix it. If I remember correctly in the GitHub link where I have the mobile buttons I have set the car up to be more prone to oversteer.
how do i make it so that when the car is in reverse the camera does not flip to the front side. I want it so that i still see the back of the car when in reverse and not the front
Hmmm I would either add a check so that it doesn't move further forward. Something like if (distance of camera to car is bigger than 5) only then move the camera
Hello my friend thanks for great video! I have question, when i press "s" and car is going back way the front wheels are shaking and i cant go right or left side how can i fix this problem
I have fixed it in future videos, just make sure that counter steering doesn't apply if the drift angle is bigger than 120 So If(driftangle>120) {Countersteer=0}
Hi there, I don't know if you are still active here, I really loved your Tutorial, You gained a sub here, I was wondering can you tell me how to implement soft body physics destruction for my game? It is going to be a Demolition Derby kind of game.
hey dude thanks for these awesome tut series, can you make a tutorial related to replay system like asphalt 9 when race finished, a replay of race with all its events called ,, kindly make a detailed tut related to it
It probably has something to do with the pivot points of the wheels, try to put them inside an empty game object that is going to be in place of the wheels and use that as the wheel mesh. Hope it helps
Most of the high end assets use the wheel colliders physics from Unity to achieve realistic driving. Now if you want an even more realistic car, you can do it through scripts
Oh, I meant like armature or bones, such as for rigging characters. But using it for cars instead. Anyways, I think I'll just do it the way you do it. Thanks for your tutorials and for being so responsive!
@@nanousis I found even more errors sadly.. it says "Assets\CarController.cs(59,41): error CS0266: Cannot implicitly convert type 'double' to 'float'. An explicit conversion exists (are you missing a cast?)" "Assets\CarController.cs(40,29): error CS1501: No overload for method 'Angle' takes 3 arguments" "Assets\CarController.cs(71,27): error CS1061: 'WheelCollider' does not contain a definition for 'steeringAngle' and no accessible extension method 'steeringAngle' accepting a first argument of type 'WheelCollider' could be found (are you missing a using directive or an assembly reference?)" "Assets\CarController.cs(72,27): error CS1061: 'WheelCollider' does not contain a definition for 'steeringAngle' and no accessible extension method 'steeringAngle' accepting a first argument of type 'WheelCollider' could be found (are you missing a using directive or an assembly reference?)" uh oh.. help
Hi sorry I have too many errors i will rephrase what I said.. So the car goes forwards and backwards which is fine but then while going forward and trying to turn to the left or right the car doesn't even turn left or right.. I need help and this tutorial is helping me alot..
@@nanousis nothing changed( the problem is that the particles spawn in the opposite direction like 180° but in script i can't understand Instantiate value that spawns smoke in this direction
@@nanousis you could zip the file and upload it to google drive, but I was just having lots of issues which I don't really know how to fix and I don't have a lot of time so I can't go through the whole video. I'll try that out tho, thanks
using System.Collections; using System.Collections.Generic; using UnityEngine; public class car_contrallar : MonoBehaviour { public WheelColliders colliders; public WheelMeshes wheelMesh; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { ApplyWheelPositions(); } void ApplyWheelPositions() { UpdateWheel(colliders.FL, wheelMesh, wheelMesh.FL); } void UpdateWheel(WheelCollider coll, MeshRenderer WheelMesh) { Quaternion quat; Vector3 position; coll.GetWorldPose(out position, out quat); WheelMesh.transform.position = position; WheelMesh.transform.rotation = quat; } } [System.Serializable] public class WheelColliders { public WheelCollider FL; public WheelCollider FR; public WheelCollider RL; public WheelCollider RR; } [System.Serializable] public class WheelMeshes { public MeshRenderer FL; public MeshRenderer FR; public MeshRenderer RL; public MeshRenderer RR; }
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CarController : MonoBehaviour { public List WheelColliders; public List WheelMeshes; public GameObject centerofmass; void Start() { // GetComponent().centerOfMass = centerofmass.transform.position; } void Update() { updateWheels(); } void updateWheels() { updateWheel(WheelColliders[0], WheelMeshes[0]); updateWheel(WheelColliders[1], WheelMeshes[1]); updateWheel(WheelColliders[2], WheelMeshes[2]); updateWheel(WheelColliders[3], WheelMeshes[3]); } void updateWheel(WheelCollider col, MeshRenderer wheelmesh) { Quaternion rot; Vector3 pos; col.GetWorldPose(out pos, out rot); wheelmesh.transform.position = pos; wheelmesh.transform.rotation = rot; } } my wheels get away from the car slowly when I start the game and car flips over. Help please