So I’ve got two problems right now, I finally managed to get my vehicle reasonably stable but I’ve run into problems with my wheel collider settings because I can tweak things but I just don’t know what to do in order to fix these types of problems.
The first and most obvious one is that I’ve got a bad case of juddering going on despite the fact that the vehicle is completely still, the second one is that at top speeds the vehicle slides in the direction it’s travelling like it’s on ice and doesn’t stop. I can get it to stop after fiddling around with other settings but then the instability comes back and the car rolls over very easily.
Juddering
Instability
Now before you say, I have already checked out the anti-roll bar tutorial, perhaps it might be a good idea for me to see if I can look at their settings however I want to know exactly what sideways friction does and so on I guess so I can fine tune everything to suit what I want the buggy to react like.
Damper seems too high (4000) for the vehicle’s mass (1500). In a four-wheeled car, the rule of thumb is starting with the damper in all wheels being the same value as the vehicle’s mass. Then increase it if you want stiffer suspension. I’d recommend the top limit for the damper to be twice the vehicle’s mass.
Center of mass seems not to have been set, so Unity has placed it at the default position based on the colliders. I’d try setting the center of mass explicitly so it’s located around the middle point of the wheels in that car.
It seems to have fixed a lot of the problems but now I’m running into the stability issue again where the vehicle keeps trying to flip over, what settings would I need to play with to make that work right? Thanks for your advice so far on the damper settings and centre of mass as that seems to have fixed the main stuff.
Actually one moment, I’m trying to make it so the angles are similar to that of the Halo Warthog, note how when it jumps off the same sort of ramps as what I’ve made it doesn’t flip over?
I wonder if it’s to do with centre of mass now I think about it, that’s an idea, nope nevermind, didn’t do a thing.
First, I’d recommend you to use some camera script (smooth follow or camera orbit). Using a fixed camera like that makes very difficult to appreciate the actual behavior of the car.
The issue at 0:37 in the video (too much rotation after leaving the ramp) is surely caused by a bug in the WheelCollider damper that causes negative suspension values sometimes when the suspension is suddenly elongated. This situation occurs when leaving the ramp. Sometimes will be fine, as in the first attempt, but others it will cause unexpected rotations. The only possible workaround without additional scripts is lowering the damper and crossing fingers for it not to happen. In my case, I’ve had to implement the suspension damper myself for fixing the issue.
About the halo vehicle, its rotation rate gets lowered while the vehicle is in the air. It can be clearly observed in the jump at 0:45. When the vehicle gets too much rotation forward, the rotation rate suddenly stops. You may write a script for reproducing that behavior. For example: raise raise the rigidbody’s angular drag value if the inclination angle is too large. You may expose the parameters for the maximum angle, threshold, maximum angular drag value, etc. for providing a smooth increase in the drag when approaching the maximum angle. A solution like this would also help fixing the previous issue with the damper.
Just thought I’d say I’ve fixed a lot of stuff and I’m going to leave some things to help people out, for the camera I found a good tutorial that doesn’t over complicate things when you want to just make a simple orbiting camera.
For the problem of the vertical flipping, instead of the Halo approach, I decided to make things a bit more interesting and use the GTA V approach which is actually far simpler as well.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateVehice : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.LeftShift))
{
transform.Rotate (2, 0, 0);
}
if (Input.GetKey (KeyCode.LeftControl))
{
transform.Rotate (-2, 0, 0);
}
}
}
As you can see, just like in GTA V, this script lets you rotate the vehicle vertically using the Left CTRL and the Left SHIFT keys so when you go off a ramp or any kind of jump it will let you adjust things so the car doesn’t flip over. If I were to be extra fancy then perhaps I’d put in a bool to check whether the vehicle is grounded or not so you can only adjust the vehicle mid-air like in GTA V.
Thanks for all the help so far Edy, my only issue now is that the vehicle rolls over too damn easily I would have thought the anti-roll bar script I have would be fixing this but I don’t know whether it’s just my settings again or something else.
Yes, that’s also a nice trick. Players like to control the car when airborne.
Vehicle rolling over so easily is caused by the center of mass being located too high. Not even anti-roll bars can compensate it. Start by setting the height of the CoM at the same level of the center of the wheels, then either raise or lower it slightly for adjusting the handling.
Ahhh, thank you! I thought it rolled over easily, I’ll try that and give a video again of the result, I was wondering if it was taking into account the model itself somehow but your explanation makes more sense. I placed the CentreOfMass fairly in the centre of the overall model so if it’s as you say that will be way too high.
This information has all been really helpful thanks for all this information, like most of these threads where people just post tips I bet it will help out newbies a lot because I found it very frustrating like with saving and loading finding anything up to date or complete.
Edit: It’s a shame by the way there doesn’t seem to be any debugging tools that I’m aware of provided by Unity, correct me if I’m wrong of course but it would be nice if we had more tools so we could actually see where the anti-roll bars are and connecting and so on. I wouldn’t have thought to look at the CentreOfMass you see if you hadn’t mentioned it as an issue.