- Home /
Can you make a freely spinning WheelCollider in Unity5?
I'm simulating a small aeroplane and I was using WheelColliders in Unity 4.5 for the wheels. Since switching to Unity 5 the wheels resist any kind of external forces. When I spin up the propeller and apply forces to the Rigidbody, the plane flips onto its nose!
Here's the problem demonstrated on a cube with wheels:
The wheels are default WheelColliders, the cube has mass 2000 and I'm applying a force of 10,000 using a very simple script:
public class Truck : MonoBehaviour
{
bool push;
void Update() {
push = Input.GetKey("p");
}
void FixedUpdate() {
if (push)
GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, 10000));
}
}
Other experiments:
The truck will roll if you apply a small force before the truck "lands" when the level starts, so it hits the ground rolling ever so slightly.
The truck will also roll if you incline the slope to greater than 1.4 degrees (??). Anything less than that and it stays glued to the ground.
What's going on here?
[1]: /storage/temp/43744-physicstest.zip
I tried to recreate your issue, but with completely out of the box settings, sans offsetting centers on (roughly) the corners of a 1,1,3 scale unity box with 2000 rigidbody mass, it rolls just fine.
Perhaps there's something else in your script that's causing the strange behavior, because i can move the box with even exceptionally small amounts of force.
There's really not much else going on in the script, which is why I was confused. You're using the default settings on the Unity 5 WheelCollider?
(Edited my post to add the complete code after deleting all the other stuff.)
There must be something wrong with hierarchy, or scene. I just made a 1,1,3 scale box with 4 completely default setting wheelcolliders, outside of their offsets, attached to empty gameobjects as its children in a similar setup to your's and it works fine.
Try using transform.forward*10000 ins$$anonymous$$d of vector3(0,0,10000)
Really appreciate you looking into it, even if you're not seeing the same results.
I've tried it with a hierarchy like this:
- Truck
Cube
Wheel
Wheel
Wheel
Wheel
and like this:
- Cube
Wheel
Wheel
Wheel
Wheel
Both of which exhibit the same behaviour. transform.forward*10000 is equal to 0, 0, 10000 but I tried it anyway and see the same problem.
I've attached a zip file of an absolute bare bones project that has the problem on my version of Unity (5.0.0f4 Personal). I created it completely from scratch just now using default settings.
https://www.youtube.com/watch?v=jNySyx2RrP0
check this video to solve problem of wheel collider bouncing on unity5
Answer by Baroque · Apr 03, 2015 at 05:21 AM
On further research, this seems to be a known issue with the WheelColliders in Unity 5.
See these forum posts:
http://forum.unity3d.com/threads/unityfs-flight-simulation-toolkit.171604/page-8
http://forum.unity3d.com/threads/unity-5-wheelcollider-component-is-unusable.307099/
There is a simple workaround though: Create an Awake() function that gives the wheels a non-zero motor torque and they will spin freely.
void Awake() {
foreach (WheelCollider w in GetComponentsInChildren<WheelCollider>())
w.motorTorque = 0.000001f;
}
This is low enough that the vehicle won't start driving away but apparently enough that the wheels will turn freely.
Thanks, that resolved my issue, but I have one question. I have a model which rotates based on the wheels rpm and this decreases the rpm which causes a constant rotation. I could check and only rotate the wheel if the motortorque does not match 0.000001f, but then it does not rotate if it is freely rolling.
Here is my code: (wheelVisualRotate would be my model)
if (wheelCollider.motorTorque != 0.000001f)
{
wheelVisualRotate.Rotate(-wheelCollider.rpm / 60 * 360 * Time.deltaTime, 0, 0);
}
Answer by JigneshKoradiya · Jul 08, 2015 at 04:04 PM
https://www.youtube.com/watch?v=jNySyx2RrP0
check this video to solve problem of wheel collider bouncing on unity5
Your answer
Follow this Question
Related Questions
Wheelcollider Settings to Match Default Unity 4 0 Answers
Character Controller Pushes Car With Wheel Colliders? 0 Answers
Simulating wheels without a wheel collider? 1 Answer
Do wheel colliders account for wheel width? 1 Answer
WheelCollider not calling OnTriggerEnter() of a BoxCollider trigger. 0 Answers