- Home /
Question by
aejuergensen · Nov 29, 2021 at 05:31 PM ·
collisionphysicswheelcollider
Wheel Colliders are nonfunctional and im unable to find any cause.
a simple car controller from a tutorial i found: https://www.youtube.com/watch?v=Z4HA8zJhGEk
public class CarController : MonoBehaviour
{
private const string H = "Horizontal";
private const string V = "Vertical";
private float horizontalInput;
private float verticalInput;
private float currentBrakeForce;
private float currentSteerAngle;
private bool isBraking = false;
[SerializeField] private float motorForce;
[SerializeField] private float brakeForce;
[SerializeField] private float maxSteerAngle;
[SerializeField] private WheelCollider frontLeft;
[SerializeField] private WheelCollider frontRight;
[SerializeField] private WheelCollider backLeft;
[SerializeField] private WheelCollider backRight;
[SerializeField] private Transform frontLeftTransform;
[SerializeField] private Transform frontRightTransform;
[SerializeField] private Transform backLeftTransform;
[SerializeField] private Transform backRightTransform;
private void FixedUpdate()
{
GetInput();
HandleMotor();
HandleSteering();
UpdateWheels();
}
private void GetInput()
{
horizontalInput = Input.GetAxis(H);
verticalInput = Input.GetAxis(V);
isBraking = Input.GetKey(KeyCode.Space);
}
private void HandleMotor()
{
frontLeft.motorTorque = verticalInput * motorForce;
frontRight.motorTorque = verticalInput * motorForce;
//currentBrakeForce = isBraking ? brakeForce : 0f;
if (isBraking)
{
ApplyBraking();
}
}
private void ApplyBraking()
{
frontLeft.brakeTorque = currentBrakeForce;
frontRight.brakeTorque = currentBrakeForce;
backLeft.brakeTorque = currentBrakeForce;
backRight.brakeTorque = currentBrakeForce;
}
private void HandleSteering()
{
currentSteerAngle = maxSteerAngle * horizontalInput;
frontLeft.steerAngle = currentSteerAngle;
frontRight.steerAngle = currentSteerAngle;
}
private void UpdateWheels()
{
UpdateSingleWheel(frontLeft, frontLeftTransform);
UpdateSingleWheel(frontRight, frontRightTransform);
UpdateSingleWheel(backLeft, backLeftTransform);
UpdateSingleWheel(backRight, backRightTransform);
}
private void UpdateSingleWheel(WheelCollider wheelCol, Transform wheelTrans)
{
Vector3 pos;
Quaternion rot;
wheelCol.GetWorldPose(out pos, out rot);
wheelTrans.rotation = rot;
wheelTrans.position = pos;
}
}
the problem is my wheels just fall through the ground like so: https://imgur.com/a/y6VnKV6 skateboard has rigidbody and a child with a box collider, and separate objects for wheel meshes and colliders. when getting horizontal input i can see that the wheel meshes spin and turn left and right properly but the wheel colliders just do nothing... they don't even collide with the ground. Do i need mesh colliders on the wheels? I'm really at a loss here as im not getting any errors anywhere and everything i've scripted appears to be working as intended, do wheel colliders just not work anymore?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613045934im_/https://answers.unity.com/themes/thub/images/avi.jpg)