• 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 /
  • Help Room /
avatar image
0
Question by spagett39 · Sep 24, 2015 at 07:45 AM · scripting problemwheelcollidertransform.rotate

Rear wheels of car spinning incorrectly

Hello all,

So I've been working on a car tutorial and have gotten my vehicle up and running, which is great (I downloaded a free car model from the asset store just to mess around with it and focus on learning some scripting basics). The front wheels rotate in the correct direction, but unfortunately the rear wheels have been exhibiting some erratic behavior. They rotate in the correct direction, but at a faster rate than my front two wheels. I did not follow the Unity car tutorial but another youtube one instead (probably my first mistake) as I didn't realize that there was a unity-provided one until I started looking for answers to my problem on this site. My car movement script (in c#) is as follows:

using UnityEngine; using System.Collections;

public class carMover2 : MonoBehaviour {

 public WheelCollider wheelFL;
 public WheelCollider wheelFR;
 public WheelCollider wheelRL;
 public WheelCollider wheelRR;

 public Transform wheelFLTrans;
 public Transform wheelFRTrans;
 public Transform wheelRLTrans;
 public Transform wheelRRTrans;

 public float maxTorque = 50f;
 public float turnRadius = 20f;


 // Use this for initialization
 void Start () {


 }
 
 // Update is called once per frame
 void FixedUpdate () {

     wheelFL.steerAngle = turnRadius * Input.GetAxis ("Horizontal");
     wheelFR.steerAngle = turnRadius * Input.GetAxis ("Horizontal");

     wheelRL.motorTorque = maxTorque * Input.GetAxis ("Vertical");
     wheelRR.motorTorque = maxTorque * Input.GetAxis ("Vertical");
         
 }

 void Update (){

     wheelFLTrans.Rotate (wheelFL.rpm / 60 * -360 * Time.deltaTime, 0, 0);
     wheelFRTrans.Rotate (wheelFR.rpm / 60 * 360 * Time.deltaTime, 0, 0);
     wheelRLTrans.Rotate (wheelRL.rpm / 60 * -360 * Time.deltaTime, 0, 0);
     wheelRRTrans.Rotate (wheelRR.rpm / 60 * 360 * Time.deltaTime, 0, 0);

 }

}

As you can see from the code, it's currently rear-wheel drive. The front left and rear left tires are at a -360 rotation because when they were duplicated from the right tire, it the model was flipped 180 degrees so that it was facing correctly. The models for the wheels are children of empty game objects, which are used as the wheel transforms. I duplicated the wheel transform game objects and placed them in different empty game objects which are the wheel colliders (the children wheel models were deleted from the wheel collider game objects). The front two wheel transform game objects were duplicated to create the rear wheel ones. I'm wondering if there's some correlation here as to why the rear tires are spinning at a faster rate and with a 'jerky' motion, but I really can't pinpoint the problem for sure.

Here is the vehicle in wireframe mode which shows the colliders:

alt text

And here's a shot of the hierarchy to give you an idea of how the wheel transforms and wheel colliders are grouped currently:

alt text

Here's a .gif of how the rear wheels currently move: https://media.giphy.com/media/26BkLC1hz8ny8wdby/giphy.gif The front feels rotate well, and the rear wheels, while rotating in the correct direction. are pretty much on crack. Please let me know if there's any more info I can provide for you guys! Thanks in advance.

hierarchy.jpg (21.1 kB)
wire.jpg (57.2 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ownerfate · Jan 03, 2018 at 11:30 PM

I think it's due to the 2 -360, when it's actually played, the left side of the car ( Right side: facing the front ) spins in reverse.

( i would say, do 360 across the board, and just make new wheelColliders and copy-paste the variables )

Comment
Add comment · Show 1 · 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 ownerfate · Jan 03, 2018 at 11:31 PM 0
Share

2015 ( you may have already solved this issue... by now... )

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

30 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

Related Questions

How to rotate wheel colliders on the Y axis since they can't be rotated in the editor? 0 Answers

Is there a way to make OVR tracking space follow player rotation? 1 Answer

Error with calling events from other scripts 3 Answers

getting a NullReferenceException error and can't see why. 1 Answer

What changed in 2018.3 that prevents teleporting the FPSController in Standard Assets 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