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 TPierce89 · May 26, 2017 at 04:57 AM · c#wheelcollidervehiclewheelwheels

How do I get my wheel mesh to rotate on the proper axis?

I have my model setup with wheel colliders and it drives fine. Everything is working well, including the position of the wheel mesh to simulate suspension. My only issue is that when I run the game, my wheels rotate 90 degrees on the Y axis and then roll along sideways. How can I rotate the mesh in the script so that it displays properly? I mainly only need position, but using wheel.getworldpose forces me to use Quaternion and Vector3. Can I do this without using Quaternion?

Heres an Image... alt text

And heres the code Im using to update my wheel position and rotation...

  // Visual updates
     void Update()
     {
         if (!driveable)
         {
             return;
         }
 
         // SETUP WHEEL MESHES
 
         // Turn the mesh wheels
         frontLeftWheelWrapper.localEulerAngles = new Vector3(0, 0, steerAngle);
         frontRightWheelWrapper.localEulerAngles = new Vector3(0, 0, steerAngle);
 
         // Wheel rotation
         frontLeftWheelMesh.Rotate(0, 0, wheelFL.rpm / 60 * 360 * Time.deltaTime);
         frontRightWheelMesh.Rotate(0, 0, wheelFR.rpm / 60 * 360 * Time.deltaTime);
         rearLeftWheelMesh.Rotate(0, 0, wheelRL.rpm / 60 * 360 * Time.deltaTime);
         rearRightWheelMesh.Rotate(0, 0, wheelRR.rpm / 60 * 360 * Time.deltaTime);
 
         //Wheel Position
         foreach (WheelCollider wheel in m_Wheels)
         {
 
             Quaternion q;
             Vector3 p;
             wheel.GetWorldPose(out p, out q);
 
             // Assume that the only child of the wheelcollider is the wheel shape.
             Transform shapeTransform = wheel.transform.GetChild(0);
             shapeTransform.position = p;
             shapeTransform.rotation = q;
         }
wheelserror.png (421.4 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by JV1587 · Jun 02, 2018 at 05:44 AM

The easiest fix I have seen is to 1. Create an empty game object, 2. align empty's rotation with the car body (as in the z axis is perpendicular to the side of the car). 3. Take the wheel mesh and make it the child of the empty game object. 4. Use those newly created objects as the wheel mesh. In my experience, the way the wheel spins has to do with how the axes have been assigned on import.

So, making an object the child of an empty object allows you to essentially rotate the axes on your child without actually moving/rotating the child

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
avatar image
0

Answer by naveenkumark374 · Mar 06, 2018 at 04:43 PM

same problem man please help me may be you found that solution please

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
avatar image
0

Answer by echozulu · Jul 17, 2021 at 02:43 AM

I ended up having this issue as well. I eventually solved it in the following manner...

  1. Created a top-level empty game object as suggested

  2. Added colliders empty game object and put all wheel colliders in game objects

  3. Added a wheels game object parallel to colliders and rotated the y-axis 90 degrees so the wheels looked correct; moved wheels to proper locations

  4. Each Wheel has its own class.. added a rotationDelta Quaternion to adjust the wheel transform during update. The class needs both the mesh and collider transform.

      void Start()
         {
             wheelTransform = GetComponentInChildren<MeshRenderer>().GetComponent<Transform>();
             rotationDelta = Quaternion.FromToRotation(wheelColliderTransform.transform.forward, wheelTransform.transform.forward);
         }
     
         void Update()
         {
             wheelCollider.GetWorldPose(out Vector3 pos, out Quaternion rot);
             wheelTransform.position = pos;
             wheelTransform.rotation = rot * rotationDelta;
         }
    
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

9 People are following this question.

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

Related Questions

Wheel is wrong rotation 0 Answers

Why does my car re-align after drift into the original direction? 0 Answers

WheelCollider rotates mesh wrong 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 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