Problem using Car script from tutorial - Setting up Wheelcolliders

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! :slight_smile:

Thanks in advance!!
Thomas

Plz use a code tag under {go advanced} then {#} and not a quote tag. Anyways if your script in question is the original one, there’s no point in showing because if it works for the original one, it should work for your car too. Things to check is if you attached the correct collider, aka wheel collider and if it is set as isTrigger. Make sure it is unticked. And if there’s rigidbody involved.

Edit: Have you gone through the tutorial, i just went and have a look and the pdf teaches how to assemble a car. Perhaps you missed anything?

Hi Zine,

As far as I can see, I got all the scripts and hierarchy the same. The wheels on the original model are just a mesh filter and mesh renderer, the weelcolliders are set up through the script…

I did find out something interesting just now: If I copy the DiscBrakeXX > WheelXX.2 from the original model to the new model, and assign the new diskbrake to the script on the new model, it Does work… Only that combination though, If I use just an original wheel or an original DiscBrake, it doesn’t do anything…

Ow and yeah, i’ve been through the tutorial tons of times, and used these scripts a lot for testing purposes… Although i just thought of something I haven’t tried yet, use the new wheels on the old car… Trying it now!