Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by rugvedkhandekar · Mar 10, 2018 at 06:50 PM · wheel colliders

Wheel Collider Bouncing insanely.,Wheel collider bouncing insanely

I took a cube, applied rigid body to it. I made an empty object added wheel collider to it, and made it a child of the cube. Now when I play the scene, the Cube bounces off the surface to infinity. Why? and How do I fix it??

Thanks and regards in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by stuartiannaylor · Nov 03, 2019 at 01:44 AM

I don't know :) Seems to be keeping the root as a empty object with the rigid body on that. Also have the wheel colliders in a child empty object that is a child of the root. That seems to have much better effect and keeps things clearer and more organisable, but read the tutorial.

I was the same and just ran through this little tutorial. https://docs.unity3d.com/Manual/WheelColliderTutorial.html

I haven't a clue why placing in empty objects as the above works and what I have done before hasn't but try the above

I am a noob also so forgive my hacking but with multi-axle and multi steer things didn't work, so I added a really rough approximation routine. Then wondered why does this thing roll so easy and added another rough approximation of an anti roll bar. Still confused of how much contact area a wheel actually gets as tyres compress and on softer surfaces wheels dig in and gain traction. But hey my script is here use the above tutorial by creating objects just as it does and give that a try then it becomes very easy just to attach whatever you need. Apply the script to the root empty object and away you go.

  using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
  
 [System.Serializable]
 public class AxleInfo
 {
     public WheelCollider leftWheel;
     public WheelCollider rightWheel;
     public bool motor;
     public bool steering;
  
 }
  
 public class SimpleCarController : MonoBehaviour
 {
     public List<AxleInfo> axleInfos;
     public float maxMotorTorque = 3000.0f;
     public float maxSteeringAngle = 25.0f;
     public float antiRoll = 5000.0f;
  
     // finds the corresponding visual wheel
     // correctly applies the transform
     public void ApplyLocalPositionToVisuals(WheelCollider collider)
     {
         if (collider.transform.childCount == 0)
         {
             return;
         }
  
         Transform visualWheel = collider.transform.GetChild(0);
  
         Vector3 position;
         Quaternion rotation;
         collider.GetWorldPose(out position, out rotation);
  
         visualWheel.transform.position = position;
         visualWheel.transform.rotation = rotation;
     }
  
     public void FixedUpdate()
     {
         float motor = maxMotorTorque * Input.GetAxis("Vertical");
         float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
      
         for (int i = 0; i < axleInfos.Count; i++)
             {
  
             WheelHit hit;
             float travelL = 1.0f;
             float travelR = 1.0f;
  
             bool groundedL = axleInfos[i].leftWheel.GetGroundHit(out hit);
             if (groundedL)
                 travelL = (-axleInfos[i].leftWheel.transform.InverseTransformPoint(hit.point).y - axleInfos[i].leftWheel.radius) / axleInfos[i].leftWheel.suspensionDistance;
             bool groundedR = axleInfos[i].rightWheel.GetGroundHit(out hit);
             if (groundedR)
                 travelR = (-axleInfos[i].rightWheel.transform.InverseTransformPoint(hit.point).y - axleInfos[i].rightWheel.radius) / axleInfos[i].rightWheel.suspensionDistance;
  
             float antiRollForce = (travelL - travelR) * antiRoll;
          
             if (groundedL)
                 GetComponent<Rigidbody>().AddForceAtPosition(axleInfos[i].leftWheel.transform.up * -antiRollForce,
                        axleInfos[i].leftWheel.transform.position);
             if (groundedR)
                 GetComponent<Rigidbody>().AddForceAtPosition(axleInfos[i].rightWheel.transform.up * antiRollForce,
                        axleInfos[i].rightWheel.transform.position);
  
             if (axleInfos[i].steering)
              
             {
                 if (i + 1 <= axleInfos.Count / 2)
                 {
                     axleInfos[i].leftWheel.steerAngle = steering / (1 + i);
                     axleInfos[i].rightWheel.steerAngle = steering / (1 + i);
                 }
                 else
                 {
                     axleInfos[i].leftWheel.steerAngle = -steering / (1 + axleInfos.Count - i);
                     axleInfos[i].rightWheel.steerAngle = -steering / (1 + axleInfos.Count - i);
                 }
             }
             if (axleInfos[i].motor)
             {
                 axleInfos[i].leftWheel.motorTorque = motor / axleInfos.Count / 2;
                 axleInfos[i].rightWheel.motorTorque = motor / axleInfos.Count / 2;
             }
  
  
             ApplyLocalPositionToVisuals(axleInfos[i].leftWheel);
             ApplyLocalPositionToVisuals(axleInfos[i].rightWheel);
         }
     }
 }

If anyone fancies cleaning up my horrid code please do. Really each axles distance from the front if a rear axle and from rear if rear to the centre of the vehicle should give the tangent of what the same turning circle should be for the current axle, via its distance to centre of turn. I thought about it and said hey way too much maths and just divided by axle number. Being zero based it was +1 1st axle / 1 so full steer value 2nd /2 50% 3rd /3 33 % and so on seems to work with 8 wheels maybe someone will do the proper maths. With above 4 wheels (2 axles) it checks if we are over half the number of axles and then those wheels steer in the opposite action to the front so you actually turn rather than skit sideways. You can select each axle if its powered or steers.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

74 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics - Using wheel colliders for 2d 1 Answer

Wheel collider problems 0 Answers

Set a boolean to true once the wheel collides with two planes? 1 Answer

Setting Wheelcollider BrakeTorque to 0 does not release brake 0 Answers

Finding suspension values 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges