Wheel Colliders stop working when hitting sharp angles.

What would cause wheel colliders in general to stop working when either getting stuck or hitting sharp angles? My vehicle can hit walls and still continue driving but if I try to hit or drive up a slope my wheel colliders stop working entirely. Its’ almost as if it has no traction or the wheel isn’t touching. I was thinking that maybe my rigidbody falls asleep but i have two ways of keeping it “awake” within my code.

using UnityEngine;
using System.Collections;

public class broncotest : MonoBehaviour
{
		public Rigidbody vehicle;
		//
		public WheelCollider flc;
		public WheelCollider frc;
		public WheelCollider lrc;
		public WheelCollider rrc;
		//
		public Transform tfl;
		public Transform tfr;
		public Transform tlr;
		public Transform trr;
		public Transform com;
		//
		public Vector3 vfl;
		public Vector3 vfr;
		public Vector3 vlr;
		public Vector3 vrr;
		public Vector3 vcom;//vector3 for center of mass object
		//
		public WheelFrictionCurve fc_flc;
		public WheelFrictionCurve fc_frc;
		public WheelFrictionCurve fc_lrc;
		public WheelFrictionCurve fc_rrc;
//		public float flsfric;//front left side friction curve
//		public float frsfric;//front right side friction curve
//		public float lrsfric;//left rear side friction curve
//		public float rrsfric;//right rear side friction curve

		//
		public bool overturned;//yes no check if player is upside down.
		public bool preverse;//yes no check if player is in reverse. 
		public bool stalled;//yes no check if player has stalled. based on either damaged or weapon hit with.
		public bool destroyed;//yes no check if player has been destroyed.
		public bool isEmergencyBraking;
		public bool isFlGrounded;//is front left tire grounded?
		public bool isFrGrounded;//is front right tire grounded?
		public bool isLrGrounded;//is left rear tire grounded?
		public bool isRrGrounded;//is right rear tire grounded?
		public bool isMph;
		public bool isKph;
		//
		public float comlz = 0f;
		public float comly = 0.35f;
		public float comlx = -.96f;
		public float comrz = 0f;
		public float comry = 0.35f;
		public float comrx = .96f;
		public float comnz = 0f;
		public float comny = 0f;
		public float comnx = 0f;
		//
		public float totalcondition;//the total average health for the player
		public float conflc;//condition of front left tire
		public float confrc;//condition of front right tire
		public float conlrc;//condition of left rear tire
		public float conrrc;//condition of right rear tire
		public float conmotor;//condition of motor
		//
		public float forward;//general movement. Doesn't count speed. 1 = forward / -1 = reverse.
		public double mph;//MPH speed check.
		public double kph;//KPH speed check.
		public float mphconvert;//dbl to float
		public float kphconvert;//dbl to float
		public float minmph = 0;//MPH speed min check.
		public float minkph = 0;//KPH speed min check.
		public float maxmph = 120;//MPH speed max check.
		public float maxkph = 193;//KPH speed max check.
		public float clampmph;//clamp base for mph
		public float clampkph;//clamp base for kph
		//public float reverse;
		public float mboost = 30f;
		public float fspeed = 30f; //should always be the same speed as driving forward.
		public float rspeed = 15f; //reverse speed. shouldn't be too fast.
		public float lrrpm;
		public float rrrpm;
		//public float rboost = 15f;
		//private float mmin = -15f;
		//private float mmax = 30f;
		//
		public float steering;
		private float sboost = 20f;
		//private float smin = -20f;
		//private float smax = 20f;
		//
		public float braking;
		private float bboost = 50f;
		//private float bmin = 0f;
		//private float bmax = 10f;
		//
		public float lrtorque;
		public float rrtorque;
		public float lsteering;
		public float rsteering;
		public float lbraking;
		public float rbraking;


		// Use this for initialization
		void Start ()
		{
				//isMph = true;
				//isKph = false;
				vehicle.WakeUp ();//wake up pls
		}

		void Update ()
		{
		}
		// Update is called once per frame
		void FixedUpdate ()
		{
//				mph = vehicle.velocity.sqrMagnitude * 2.237;//MPH
//				kph = vehicle.velocity.sqrMagnitude * 3.6;//kph
//				mphconvert = (float)mph;
//				kphconvert = (float)kph;
//				clampmph = Vector3.ClampMagnitude (mphconvert, minmph, maxmph);//clamp for min / max MPH
//				clampkph = Mathf.Clamp (kphconvert, minkph, maxkph);//clamp for min / max KPH
				vehicle.centerOfMass = com.localPosition;
				//vehbalancer ();
				healthmanager ();//PLAYER HEALTH MANAGER. EACH INDIVIDUAL PLAYER / AI NEEDS THIS
				inputmanager ();//MANAGES PLAYER INPUT
				wheelgrounded ();//mostly for debugging i guess. checks all wheels if they are touching ground.
				vehiclestabilizer ();
				if (vehicle.IsSleeping ()) {
						vehicle.WakeUp ();//pls
				}
		}

		void inputmanager ()
		{
				fc_flc = flc.sidewaysFriction;
				fc_frc = frc.sidewaysFriction;
				fc_lrc = lrc.sidewaysFriction;
				fc_rrc = rrc.sidewaysFriction;
				vfl = tfl.localEulerAngles;
				vfr = tfr.localEulerAngles;
				vlr = tlr.localEulerAngles;
				vrr = trr.localEulerAngles;
				//
				forward = Mathf.Clamp (Input.GetAxis ("Vertical"), -1, 1);
				steering = Mathf.Clamp (Input.GetAxis ("Horizontal"), -1, 1);
				braking = Mathf.Clamp (Input.GetAxis ("Braking"), 0, 1);
				//find if upside down with collider.isGrounded();
				//
				lrc.motorTorque = forward * mboost;
				rrc.motorTorque = forward * mboost;
				//frc.motorTorque = forward * mboost;
				//flc.motorTorque = forward * mboost;
				//
				lrc.brakeTorque = braking * bboost;
				rrc.brakeTorque = braking * bboost;
				//
				flc.steerAngle = steering * sboost;
				frc.steerAngle = steering * sboost;
				vfl.y = steering * sboost;
				vfr.y = steering * sboost;
				//_____________________________________________________//
				//
				lrrpm = Mathf.Clamp (lrc.rpm, 0, 100);
				rrrpm = Mathf.Clamp (rrc.rpm, 0, 100);
				lrtorque = lrc.motorTorque;
				rrtorque = rrc.motorTorque;
				vlr.x = lrrpm;
				vrr.x = rrrpm;
				vfl.x = lrrpm;
				vfr.x = rrrpm;
				tlr.localEulerAngles = vlr;
				trr.localEulerAngles = vrr;
				tfl.localEulerAngles = vfl;
				tfr.localEulerAngles = vfr;
				//
				lsteering = flc.steerAngle;
				rsteering = frc.steerAngle;
				//
				lbraking = lrc.brakeTorque;
				rbraking = rrc.brakeTorque;
				//
				if (Input.GetButtonDown ("Braking")) {
						isEmergencyBraking = true;
						if (lrc.isGrounded) {
								fc_lrc.stiffness = 0.1f;
								fc_rrc.stiffness = 0.1f;
						}
				} else if (Input.GetButtonUp ("Braking")) {
						isEmergencyBraking = false;
						if (rrc.isGrounded) {
								fc_lrc.stiffness = 1f;
								fc_rrc.stiffness = 1f;
						}
				}
				if (forward > 0) { //Means player is trying to go forward
						mboost = fspeed;//sets to forward speed. Each vehicle will have a different speed. 
				} else if (forward < 0) {//Means player is trying to reverse
						mboost = rspeed;//set reverse speed to lower number than forward. Seems realistic. Each vehicle will have a different speed. 
				} 
				GameObject[] wcobj = GameObject.FindGameObjectsWithTag ("wheelcollider");
				foreach (GameObject wc in wcobj) {
						if (wc.transform.root.tag == "Player") {
								//OK COOL ITS' THE PLAYER. WHAT NOW?
						} else {
								//NOPE NOT THE PLAYER. MUST BE AI
						}
						if (wc.GetComponent<WheelCollider> ().isGrounded == false) {
								if (wc.transform.root.eulerAngles.y >= 90 && wc.transform.root.eulerAngles.y <= 270) { //90 \ 270. BETWEEN THESE TWO MEANS ON SIDES OR UPSIDE DOWN
										//ROLL OVER VEHICLE THAT THESE WHEEL COLLIDERS BELONG TO. NEED TO PREVENT ALL PLAYERS / AI FROM BEING FLIPPED.
								} else {
										//MUST HAVE AT LEAST ONE TOUCHING THE GROUND.
								}
						}
			
				}
		}

		void vehbalancer ()
		{//THE CENTER OF MASS SYSTEM. 
				//----------------|-----------------//
				//----------------|-----------------//
				//----------------|-----------------//
				//------------/////////-------------//
				//------------//-----//-------------//
				//--------____//--+--//____---------//
				//------------//-----//-------------//
				//------------/////////-------------//
				//----------------|-----------------//
				//----------------|-----------------//
				//----------------|-----------------//
				//THE IDEA IS TO HAVE THE CENTER OF MASS MOVE WITH VEHICLE INSTEAD OF USING "STABILIZER BARS".
				//TURNING LEFT CAUSES THE CENTER OF MASS TO MOVE TO THE LEFT JUST ENOUGH TO BALANCE THE CAR WITHOUT TOPPLING OVER
				//TURNING RIGHT CAUSES THE CENTER OF MASS TO MOVE TO THE LEFT JUST ENOUGH TO BALANCE THE CAR WITHOUT TOPPLING OVER
				//NEED TO FIGURE OUT A WAY TO CHECK IF VECHILE IS UPSIDE DOWN. 
				vcom = com.localPosition;
				if (steering < 0) {//must be going left?
						Vector3 comleft = new Vector3 (comlx, comly, comlz);
						vcom = comleft;
				} else if (steering > 0) {//must be going right?
						Vector3 comright = new Vector3 (comrx, comry, comrz);
						vcom = comright;

				} else if (steering == 0) {
						Vector3 comneutral = new Vector3 (comnx, comny, comnz);
						vcom = comneutral;
				}
				com.localPosition = vcom;

		}

		void vehiclestabilizer ()
		{

		}

		void wheelgrounded ()
		{//FOR DEBUGGING USE.
				if (flc.isGrounded) {
						isFlGrounded = true;
				} else {
						isFlGrounded = false;

				}
				if (frc.isGrounded) {
						isFrGrounded = true;
				} else {
						isFrGrounded = false;

				}
				if (lrc.isGrounded) {
						isLrGrounded = true;
				} else {
						isLrGrounded = false;

				}
				if (rrc.isGrounded) {
						isRrGrounded = true;
				} else {
						isRrGrounded = false;
				}
		}

		void healthmanager ()
		{//manages the player health. 

		}
}

Video showing problem:

It's just a ray.

The wheel colliders shouldn't stop working because its' a "ray". I'm finding that my rpm isn't staying up. It appears that something is getting stuck and preventing the wheel collider from gaining speed once it gets "stuck" on the slope.

"Video showing problem". Your video duration time is zero, do something with that.

Not sure why the video isn't working. the link was so that the video started 20seconds in. i changed it to the regular link. https://www.youtube.com/watch?v=WuzGaYHPld4

1 Answer

1

Ok, i was able to correct it. It was a mix of the wheel colliders being too small and my vehicle model’s tires being poorly made. I believe that I read a couple times on forums & tutorials that you want the wheel colliders to be exactly the same size as the model’s wheels so thats what I did.

My guess what was happening was that the wheel collider wasn’t fully touching the ground and wasn’t “distributing” the full wheel torque. Once the vehicle was on the slope, only a very small percentage of the collider was only powering the wheels. I increased the wheel radius from 0.45 to 0.465. The wheels don’t appear to be floating and the collider is fully sending torque.