Hi there!
Can anyone tell me what’s happening with this script? The WheelColliders created starts to move with no torque… I’ve isolated everything but couldn’t find what is wrong.
Thanks in advance!
class FourWheeledTraction extends MonoBehaviour {
private var wheels = new Array();
private var wheelColliders = new Array();
private var wheelNames = new Array(
"frontLeft",
"frontRight",
"rearLeft",
"rearRight"
);
private var maxSteer = 25;
private var forwardFrictionStiffness = 0.02;
private var sidewaysFrictionStiffness = 0.02;
var speed = 0.0;
var frontAxisAt = 2.5;
var rearAxisAt = -2.5;
var frontWheelsRadius = 0.5;
var rearWheelRadius = 0.5;
var frontWheelsGap = 1.5;
var rearWheelsGap = 1.5;
public function Start()
{
for (i = 0; i < 4; i++) {
wheel = new GameObject();
wheel.transform.localPosition = Vector3.zero;
wheel.name = wheelNames*;*
-
wheels.push(wheel);*
-
wheel.transform.parent = transform;*
-
wheel.AddComponent(WheelCollider);*
-
wheelColliders.push(wheel.GetComponent(WheelCollider));*
-
}*
-
setupWheels();*
-
}*
-
public function setupWheels()*
-
{*
-
for (i = 0; i < wheels.Count; i++) {*
_ wheelColliders*.suspensionSpring.spring = rigidbody.mass / 2;_
wheelColliders_.suspensionSpring.damper = rigidbody.mass * 0.001;
wheelColliders.forwardFriction.stiffness = forwardFrictionStiffness;
wheelColliders.sidewaysFriction.stiffness = sidewaysFrictionStiffness;*_
if (wheels_.name == “frontLeft” || wheels*.name == “frontRight”) {
wheelColliders.radius = frontWheelsRadius;
if (wheels.name == “frontLeft”)
wheels.transform.localPosition = Vector3(-frontWheelsGap, frontWheelsRadius, frontAxisAt);
else*
wheels*.transform.localPosition = Vector3(frontWheelsGap, frontWheelsRadius, frontAxisAt);*_
* } else {*
_ wheelColliders*.radius = rearWheelRadius;
if (wheels.name == “rearLeft”)
wheels.transform.localPosition = Vector3(-rearWheelsGap, rearWheelRadius, rearAxisAt);
else*
wheels*.transform.localPosition = Vector3(rearWheelsGap, rearWheelRadius, rearAxisAt);
}*_
* }*
* }*
}
No IDEA! :S