- Home /
unity wheel collider settings
Hello everybody,
So I am a student working on my second concept game. I have a car downloaded from assets store, blue BMW with wheels and brakes as separated objects on the prefab and I want to move the car and the wheels with the wheel colliders. I followed a tutorial on youtube and everything is fine but the car is really slow like a snail. I set the motor force to a high number for testing to 150000 and still like a snail. the mass of the rigidbody on the car is 1750. I do not know how to set up the mass and other settings for the wheel colliders. I have pictures of the settings I am using. Can anybody help me understand where the issue is or am I missing some settings? Other thing: does anybody know how to set up the wheel colliders' spring and friction settings? Thank you very much
pictures:
code I am using:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
private const string HORIZONTAL = "Horizontal";
private const string VERTICAL = "Vertical";
private float horizontalInput;
private float verticalInput;
private float carSpeed = 150f;
private float currentSteerAngle;
[SerializeField] private float motorForce;
[SerializeField] private float maxSteeringAngle;
[SerializeField] private WheelCollider frontLeftWheelCollider;
[SerializeField] private WheelCollider frontRightWheelCollider;
[SerializeField] private WheelCollider rearLeftWheelCollider;
[SerializeField] private WheelCollider rearRightWheelCollider;
[SerializeField] private Transform frontLeftWheelTransform;
[SerializeField] private Transform frontRightWheelTransform;
[SerializeField] private Transform rearLeftWheelTransform;
[SerializeField] private Transform rearRightWheelTransform;
private void FixedUpdate()
{
GetInput();
HandleMotor();
HandleSteering();
UpdateWheels();
}
private void UpdateWheels()
{
UpdateSingleWheel(frontLeftWheelCollider, frontLeftWheelTransform);
UpdateSingleWheel(frontRightWheelCollider, frontRightWheelTransform);
UpdateSingleWheel(rearLeftWheelCollider, rearLeftWheelTransform);
UpdateSingleWheel(rearRightWheelCollider, rearRightWheelTransform);
}
private void UpdateSingleWheel(WheelCollider wheelCollider, Transform wheelTransform)
{
Vector3 pos;
Quaternion rot;
wheelCollider.ConfigureVehicleSubsteps(400f, 5, 2);
wheelCollider.GetWorldPose(out pos, out rot);
wheelTransform.rotation = rot;
wheelTransform.position = pos;
}
private void HandleSteering()
{
currentSteerAngle = maxSteeringAngle * horizontalInput;
frontLeftWheelCollider.steerAngle = currentSteerAngle;
frontRightWheelCollider.steerAngle = currentSteerAngle;
}
private void HandleMotor()
{
frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
frontRightWheelCollider.motorTorque = verticalInput * motorForce;
}
private void GetInput()
{
horizontalInput = Input.GetAxis("HORIZONTAL");
verticalInput = Input.GetAxis("VERTICAL");
}
}