hey guys … i made a car using the car physics tutorial and added stabilizer bar to keep it from rolling so everything is fine … but the reaction time in the braking and the accelerating is very slow i would be accelerating . then i click on the back button but the car keeps moving forward for another 10 seconds or something like that … and the same thing for moving back i would click accelerate but it would take a long time too … but the steering is fine
i have rb mass 1500 … and wheel colliders mass 20 … and everything else os default
here is my code …
for moving the car and updating the mesh
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarMover : MonoBehaviour {
public WheelCollider[] wheelColliders = new WheelCollider[4]; // Getting Wheel Colliders
public Transform[] wheelMeshes = new Transform[4]; // Getting Wheel Meshes to move them
public float maxTorque = 5000f;
void Update() {
UpdateMeshPos(); // Rotating the wheels
}
void FixedUpdate() {
moveCar(); // going to steer the car and move it
}
void moveCar() {
float steering = Input.GetAxis("Horizontal") * 45f;
float accelerate = Input.GetAxis("Vertical") * maxTorque;
wheelColliders[0].steerAngle = steering;
wheelColliders[1].steerAngle = steering;
wheelColliders[2].motorTorque = accelerate;
wheelColliders[3].motorTorque = accelerate;
}
void UpdateMeshPos() {
for (int i = 0; i < 4; i++) {
Quaternion quat;
Vector3 pos;
wheelColliders[i].GetWorldPose(out pos, out quat);
wheelMeshes[i].position = pos;
wheelMeshes[i].rotation = quat;
}
}
/*
void calcCenterOfMass() {
Rigidbody Player = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody>();
Debug.Log(Player.centerOfMass);
}
void setCenterOfMass() {
Rigidbody Player = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody>();
Player.centerOfMass = new Vector3(0f, 0f, 0f);
}
*/
}
and this is for the stabilizer bars … i took this from the forum …
var WheelL : WheelCollider;
var WheelR : WheelCollider;
var AntiRoll = 5000.0;
function FixedUpdate ()
{
var hit : WheelHit;
var travelL = 1.0;
var travelR = 1.0;
var groundedL = WheelL.GetGroundHit(hit);
if (groundedL)
travelL = (-WheelL.transform.InverseTransformPoint(hit.point).y - WheelL.radius) / WheelL.suspensionDistance;
var groundedR = WheelR.GetGroundHit(hit);
if (groundedR)
travelR = (-WheelR.transform.InverseTransformPoint(hit.point).y - WheelR.radius) / WheelR.suspensionDistance;
var antiRollForce = (travelL - travelR) * AntiRoll;
if (groundedL)
GetComponent.<Rigidbody>().AddForceAtPosition(WheelL.transform.up * -antiRollForce,
WheelL.transform.position);
if (groundedR)
GetComponent.<Rigidbody>().AddForceAtPosition(WheelR.transform.up * antiRollForce,
WheelR.transform.position);
}
thank you !