- Home /
Car Wheels Error/Glitch/BUG, Please help.
Hey Guys. I am creating a racing car game. I have my car functioning 99% well. It drives/stears fantastic. I have a computer car that races with you. It works beautifully. The only issue im having atm is. When i created my car i used the actual spokes inside the rim to be the rotating axis so it looks more real. But when i start the game my rims stick out the side and it looks so goofy. Should i edit my model and make the wheel one object or should i simply move the actual wheel script to a different component. Here is pictures of the actual bug.
This is the car When the rims are being stupid.
This Is The Car Behaving beautifully before i play the game.
So i was wondering if you guys have any information that could help this error. Thank you :)
Thanks mate, I didn't design it i bought this model in a pack. When you say did i check my normal setting what do you mean mate? I'm not too sure on what you mean since im a bit of a noob :)
Answer by hirenkacha · May 28, 2012 at 10:23 AM
Check your wheel colliders pivot and your wheel's pivot if you are making them reference to eachother at runtime.
Sorry mate not too sure on what you mean pivit. This is the script for the wheels if this helps.
// Define the variables used in the script, the Corresponding collider is the wheel collider at the position of // the visible wheel, the slip prefab is the prefab instantiated when the wheels slide, the rotation value is the // value used to rotate the wheel around it's axel. var CorrespondingCollider : WheelCollider; var SlipPrefab : GameObject; private var RotationValue : float = 0.0;
function Update () {
// define a hit point for the raycast collision
var hit : RaycastHit;
// Find the collider's center point, you need to do this because the center of the collider might not actually be
// the real position if the transform's off.
var ColliderCenterPoint : Vector3 = CorrespondingCollider.transform.TransformPoint( CorrespondingCollider.center );
// now cast a ray out from the wheel collider's center the distance of the suspension, if it hit something, then use the "hit"
// variable's data to find where the wheel hit, if it didn't, then se tthe wheel to be fully extended along the suspension.
if ( Physics.Raycast( ColliderCenterPoint, -CorrespondingCollider.transform.up, hit, CorrespondingCollider.suspensionDistance + CorrespondingCollider.radius ) ) {
transform.position = hit.point + (CorrespondingCollider.transform.up * CorrespondingCollider.radius);
}else{
transform.position = ColliderCenterPoint - (CorrespondingCollider.transform.up * CorrespondingCollider.suspensionDistance);
}
// now set the wheel rotation to the rotation of the collider combined with a new rotation value. This new value
// is the rotation around the axle, and the rotation from steering input.
transform.rotation = CorrespondingCollider.transform.rotation * Quaternion.Euler( RotationValue, CorrespondingCollider.steerAngle, 0 );
// increase the rotation value by the rotation speed (in degrees per second)
RotationValue += CorrespondingCollider.rpm * ( 360/60 ) * Time.deltaTime;
// define a wheelhit object, this stores all of the data from the wheel collider and will allow us to deter$$anonymous$$e
// the slip of the tire.
var CorrespondingGroundHit : WheelHit;
CorrespondingCollider.GetGroundHit( CorrespondingGroundHit );
// if the slip of the tire is greater than 2.0, and the slip prefab exists, create an instance of it on the ground at
// a zero rotation.
if ( $$anonymous$$athf.Abs( CorrespondingGroundHit.sidewaysSlip ) > 2.0 ) {
if ( SlipPrefab ) {
Instantiate( SlipPrefab, CorrespondingGroundHit.point, Quaternion.identity );
}
}
}
Sorry if script isnt well presented i dont know how to add it to code box.
@AusAndrew : Sorry for late reply. I think your wheelcollider is too much inward. Check with pulling out your wheelcolliders slightly. And check your car model's wheel's center where it is? Wheelcollider's center and your 3d wheel model's center should be get adjusted. It wld woek fine.
$$anonymous$$ate, Truly... Thank you! :) I Followed what you said and a little adjusting i got it!! Thank you! :)