- Home /
Car Movment Script not fully working!!!!!!!
I'm creating a kart game and when I stop the kart the wheel dont stop and the kart takes a very long time to stop and reverse
Im not sure why the wheels are moving so fast and not stopping when brakimh, car is going so slow and taking ages to go into reserve?
This is the code im using
using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
public float maxTorque = 5000f;
public float speed = 5000f;
public Transform centerofMass;
public WheelCollider[] wheelColliders = new WheelCollider[4];
public Transform[] tireMeshes = new Transform[4];
private Rigidbody m_rigidBody;
void Start()
{
m_rigidBody = GetComponent<Rigidbody>();
m_rigidBody.centerOfMass = centerofMass.localPosition;
}
void Update()
{
UpdateMeshesPositions();
}
void FixedUpdate()
{
float steer = Input.GetAxis ("Horizontal");
float accelrate = Input.GetAxis ("Vertical");
float finalAngle = steer * 45f;
wheelColliders [0].steerAngle = finalAngle;
wheelColliders [1].steerAngle = finalAngle;
for (int i = 0; i < 4; i++)
{
wheelColliders[i].motorTorque = accelrate * speed * maxTorque; }
}
void UpdateMeshesPositions()
{
for(int i = 0; i < 4; i++)
{
Quaternion quat;
Vector3 pos;
wheelColliders[i].GetWorldPose(out pos, out quat);
tireMeshes[i].position = pos;
tireMeshes[i].rotation = quat;
}
}
}
P.S i have tried lowering damper to 100 and that hasnt done anything to fix it also my RigidBody mass is set to 100
Answer by hi1357357 · Aug 04, 2017 at 10:14 PM
I have 3 suggestions...
It looks like it just has really bad friction. I would try turning up the friction or somthing like that. Have you checked the friction on the road? I don't think the problem is in the script.
I, personally have not had any luck with wheel colliders. I have however had some luck with capsule colliders and a hinge constraint. (If you use the hinge as the motor and the axis to turn around.) I don't know how you have any of this set up, but what happens if you replace the wheel colliders with capsule colliders, and then coded the steering without the wheel colliders.
It would be a lot easier to help if i had access to the car prefab you were using, along with the scripts and stuff so I could test it out and see what would help. But that is all the help I can give you. Maybe someone else will have better advice?
Good Luck!
I'm more than happy to send you my files that I have Let me upload them and ill send you the link
Your answer
![](https://koobas.hobune.stream/wayback/20220612131946im_/https://answers.unity.com/themes/thub/images/avi.jpg)