# Need help with coding!

I`'m a desinger and have no clue of coding and i just found this a pre made project that helps you out with placing the wheel colliders. The problem is that it places the wheels from script. That means all wheels have the same shape. But in my case i want diffrent shapes for the front and back wheels. Could some one help me out with this please?

``````using UnityEngine;
using System.Collections;

public class RearWheelDrive : MonoBehaviour {

private WheelCollider[] wheels;

public float maxAngle = 30;
public float maxTorque = 300;
public GameObject wheelShape;

// here we find all the WheelColliders down in the hierarchy
public void Start()
{
wheels = GetComponentsInChildren<WheelCollider>();

for (int i = 0; i < wheels.Length; ++i)
{
var wheel = wheels ;

// create wheel shapes only when needed
if (wheelShape != null)
{
var ws = GameObject.Instantiate (wheelShape);
ws.transform.parent = wheel.transform;
}
}
}

// this is a really simple approach to updating wheels
// here we simulate a rear wheel drive car and assume that the car is perfectly symmetric at local zero
// this helps us to figure our which wheels are front ones and which are rear
public void Update()
{
float angle = maxAngle * Input.GetAxis("Horizontal");
float torque = maxTorque * Input.GetAxis("Vertical");

foreach (WheelCollider wheel in wheels)
{
// a simple car where front wheels steer while rear ones drive
if (wheel.transform.localPosition.z > 0)
wheel.steerAngle = angle;

if (wheel.transform.localPosition.z < 0)
wheel.motorTorque = torque;

// update visual wheels if any
if (wheelShape)
{
Quaternion q;
Vector3 p;
wheel.GetWorldPose (out p, out q);

// assume that the only child of the wheelcollider is the wheel shape
Transform shapeTransform = wheel.transform.GetChild (0);
shapeTransform.position = p;
shapeTransform.rotation = q;
}

}
}
}
``````

You could modify wheelShape to be an array â€¦ then drag your different wheel (shapes) into the array, so the indexes match the wheel positions. Then, it should add the ones you want, where you want.

I think `var wheel = wheels[i];` is not showing up because of the missing code tags, i was going to say that doesnâ€™t look right, otherwise.

Iâ€™m not realy sure what to do! Shouldnâ€™t that do the job? If thats right i doesnt work!

``````    public GameObject[] wheelShape;
``````

Yes, but now when you create the shapes (in the code)

``````// here we find all the WheelColliders down in the hierarchy
public void Start()
{
wheels = GetComponentsInChildren<WheelCollider>();

for (int i = 0; i < wheels.Length; ++i)
{
var wheel = wheels[i]; // changed here, but I think this was a pasting problem from before.

// create wheel shapes only when needed
if (wheelShape[i] != null) // changed here.
{
var ws = GameObject.Instantiate (wheelShape[i]); // changed here.
ws.transform.parent = wheel.transform;
}
}
}
``````

Remember to assign the shapes in the inspector

Another error in line 48 and it says: Cannot implicitly convert type `UnityEngine.GameObject[ ]' to `boolâ€™

if that has to do with if(wheelShape) you have to adjust the code so it works with the index of the wheelShape array.

â€¦and how does that work?

Was the error on the line : if(wheelShape) ?
If so, change the foreach in that section to a for loop and use the index.

but wait, if you always have a wheel shape for every wheel, Iâ€™d just skip checking if itâ€™s not null.

Does that make sense?

Please post the updated code portion that has the issue, if you donâ€™t get itâ€¦