- Home /
unity car tutorial rear wheel ***SOLVED***
HI all, I have followed the Unity car tutorial and now changed their heh to my own. it drives fine however the wheels rotate in the opposite direction. Also the rear wheels are moved to the centre of the veh. how ever they do move back if the car is off the ground.
you can see it in this pic
the same veh works perfectly in the GOTOW tutorial Just noticed that the wheel colliders appear to be raised up unlike the front wheels.
does anyone have a fix for this?
many thanks
SOLVED
it looks as though there is a bit of code missing from the script
the part that creates the colliders is a little messed up.
the function to SetupWheel should look like this
hope it helps others that want to use their own vehs
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;
wc.sidewaysFriction = wfc;
wheel.wheelGraphic = wheelTransform;
wheel.tireGraphic = wheelTransform.GetComponentsInChildren(Transform)[1];
wheelRadius = wheel.tireGraphic.renderer.bounds.size.y / 2;
wheel.collider.radius = wheelRadius;
if (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
wheel.driveWheel = 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;
return wheel;
}
Don't forget to add your solution as an answer (Rather than just part of the question) and tag it as the accepted answer. This will make the question far more useful to anyone else running into the same issue.
Yes, and then it will also be removed from the Unanswered que (where I just found it!)
Your answer
Follow this Question
Related Questions
Scripting Question from Unity 2D project about "?" and ":" in C# 1 Answer
Use copyright models for creating a sellable system? 1 Answer
I have a problem with the infinite runner tut by mike geig 1 Answer
Tutorial for photon server who host the map? 0 Answers
Project: Space Shooter - can't assign variable scoreText 5 Answers