- Home /
car not moving straight
I am trying to make a simple car game but whenever i am pressing up arrow the car is moving to right. This is the code i am using and attached to the car gameobject
public WheelCollider wheelFL, wheelFR, wheelRL, wheelRR;
public float maxTorque = 50f;
public float steerFactor = 10f;
void Start ()
{
rigidbody.mass = 1500f;
rigidbody.centerOfMass = new Vector3(0f, -0.9f, 0f);
}
void FixedUpdate ()
{
wheelRR.motorTorque = maxTorque * Input.GetAxis("Vertical");
wheelRL.motorTorque = maxTorque * Input.GetAxis("Vertical");
wheelFL.steerAngle = steerFactor * Input.GetAxis("Horizontal");
wheelFR.steerAngle = steerFactor * Input.GetAxis("Horizontal");
}
Here is how wheel colliders are set
As from the image I guess your current car rig is not set up as the front of the car aligned towards the forward vector (Z).Its aligned towards the right vector(X).So pressing forward on keyboard will translate the car in forward vector globally which is currently the along the right side of ur car. You should re-rig the car so that the front of the car should face towards positive Z axis...
I didn't tested the script, but read this: RigidBody.mass
Try to change Rigidbody.mass = 1; in docs said that you should use between 0,1 and 10. Never larger then 10.
Edit: sethuraj is right, you should set cars front pointing Z axis not X.
ok i will try to change the direction of car to z and will let u know if it solves anything. $$anonymous$$oreover i found this link http://forum.unity3d.com/threads/62495-Question-about-WheelCollilder-vehicle-not-going-straight
where it says change the settings of wheel collider
After changing the settings it is working fine but now i am facing some new problem.
when car is moving some jerk effect is co$$anonymous$$g in the wheel.
If i understand correct then your wheels are "boucing"? $$anonymous$$aybe because of rigidbody mass? try to change it to 1.0f;
I tried both. 1. Car is facing now in z direction and move towards z but not straight. It is tilting either to left or right. 2. Changing rigidbody mass to 1.0f does not solve the jerk effect
Answer by VaibhavRocks · Jun 06, 2014 at 04:19 AM
Hey.. does anybody got the solution to this.. please let me know ..even i need urgently
Answer by florinel2102 · Sep 20, 2020 at 03:18 PM
I fixed by setting to all wheel colliders -- Sideways Friction - Extremum Slip to 0.02
Answer by zakirshikhli · Apr 13 at 03:09 PM
I fixed that, by dynamically rising sidewayFriction.extremumSlip of Front WheelColliders from 0.2f to ~2.0f - 2.5f according to car speed.
Something like this void Update(){ sideFrictionFront.extremumSlip = 0.2f + (currentSpeed / currentMaxSpeed) * 2; }
To fix most WheellColliders issues, many numbers there should be dynamically change accorind to speed and assign in real time (Update method): This is just a sample, not a complete solution:
void AssignWheelPhysics()
{
rearLeftCollider.sidewaysFriction = sideFrictionRear;
rearRightCollider.sidewaysFriction = sideFrictionRear;
frontLeftCollider.sidewaysFriction = sideFrictionFront;
frontRightCollider.sidewaysFriction = sideFrictionFront;
rearLeftCollider.forwardFriction = forwardFrictionRear;
rearRightCollider.forwardFriction = forwardFrictionRear;
frontLeftCollider.forwardFriction = forwardFrictionFront;
frontRightCollider.forwardFriction = forwardFrictionFront;
}
Your answer
Follow this Question
Related Questions
Wheel Collider - Mesh/Box Collider Problem 0 Answers
Wheelcolliders launch the car. 0 Answers
how to set initial speed of vehicle 1 Answer
Are y-axis wheelcolliders possible? 1 Answer
Perfect friction with WheelColliders 1 Answer