Hi All!
I’m failry new to Unity, and ran into a problem regarding the Car.JS script, that comes with the Car Tutorial… I can’t seem to get the wheel colliders / wheels set up on a custom car model.,. The Car just sinks in the road to where tho Collider_Bottom starts, and the car doesn’t move… I can steer though, the front wheels move…
I’ve got the hierachy in the new model set up the same way as the demo car, the car object containg the wheels as WheelXX > DiscBrakeXX > WheelXX, but it doesn’t seem to work…
This is the code in question:
function SetupWheelColliders()
{
SetupWheelFrictionCurve();
var wheelCount : int = 0;
for (var t : Transform in frontWheels)
{
wheels[wheelCount] = SetupWheel(t, true);
wheelCount++;
}
for (var t : Transform in rearWheels)
{
wheels[wheelCount] = SetupWheel(t, false);
wheelCount++;
}
}
function SetupWheelFrictionCurve()
{
wfc = new WheelFrictionCurve();
wfc.extremumSlip = 1;
wfc.extremumValue = 50;
wfc.asymptoteSlip = 2;
wfc.asymptoteValue = 25;
wfc.stiffness = 1;
}
function SetupWheel(wheelTransform : Transform, isFrontWheel : boolean)
{
var go : GameObject = new GameObject(wheelTransform.name + " Collider");
go.transform.position = wheelTransform.position;
go.transform.parent = transform;
go.transform.rotation = wheelTransform.rotation;
var wc : WheelCollider = go.AddComponent(typeof(WheelCollider)) as WheelCollider;
wc.suspensionDistance = suspensionRange;
var js : JointSpring = wc.suspensionSpring;
if (isFrontWheel)
js.spring = suspensionSpringFront;
else
js.spring = suspensionSpringRear;
js.damper = suspensionDamper;
wc.suspensionSpring = js;
wheel = new Wheel();
wheel.collider = wc;
Debug.Log(wheel.collider);
wc.sidewaysFriction = wfc;
wheel.wheelGraphic = wheelTransform;
Debug.Log(wheel.wheelGraphic);
wheel.tireGraphic = wheelTransform.GetComponentsInChildren(Transform)[1];
Debug.Log(wheel.tireGraphic);
wheelRadius = wheel.tireGraphic.renderer.bounds.size.y / 2;
Debug.Log(wheelRadius);
wheel.collider.radius = wheelRadius;
Debug.Log(wheel.collider.radius);
if (isFrontWheel)
{
Debug.Log("isFrontWheel");
wheel.steerWheel = true;
go = new GameObject(wheelTransform.name + " Steer Column");
go.transform.position = wheelTransform.position;
go.transform.rotation = wheelTransform.rotation;
go.transform.parent = transform;
wheelTransform.parent = go.transform;
}
else
Debug.Log("isRearWheel");
wheel.driveWheel = true;
return wheel;
Im using the debug.log, to see where the script runs into problems. It seems that everything works fine on
WheelFL, but for the Wheel FR cycle, it just returns the wheel.collider, wheel.wheelGraphic and the wheel.tireGraphic. After that it starts returning the DiscBrakeRL.Collider, and from then on out it returns everything as it should… Weird thing is: This doens’t seem to happen in the editor’s log → alll debug.log variables are shown?
I don’t get any major error’s at start up, just some shaders that want tangents normals, but that wouldn’t influence setting up the wheel colliders, would it?
I’ve been at it for hours now, anybody any idea on how to fix this? Like I said, I’m fairly new to unity, but do have some programming insights, so please, help a n00bie figure it out! ![]()
Thanks in advance!!
Thomas