• 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 Henrique Dantas · Dec 28, 2010 at 06:33 PM · axiscarwheels

Car tire rotating to the incorrect direction

Hey guys, i'm having a little problem with my game. I'm creating a offroad game and the problem is with my car tires. They're rotating in the X axis, but it needs to rotate forward (Z axis). I think the problem is the script, but anyway... Well, here is the script and a video showing how is the problem:

var rearWheel1 : WheelCollider; var rearWheel2 : WheelCollider; var frontWheel1 : WheelCollider; var frontWheel2 : WheelCollider;

var wheelFL : Transform; var wheelFR : Transform; var wheelRL : Transform; var wheelRR : Transform;

var steer_max = 20; var motor_max = 10; var brake_max = 100;

private var steer = 0; private var forward = 0; private var back = 0; private var motor = 0; private var brake = 0; private var reverse = false; private var speed = 0;

function Start() { rigidbody.centerOfMass = Vector3(0, -0.05, 0); }

function FixedUpdate () {

speed = rigidbody.velocity.sqrMagnitude; steer = Mathf.Clamp(Input.GetAxis("Horizontal"), -1, 1); forward = Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1); back = -1 * Mathf.Clamp(Input.GetAxis("Vertical"), -1, 0);

if(speed == 0) { if(back > 0) { reverse = true; } if(forward > 0) { reverse = false; } }

if(reverse) { motor = -1 * back; brake = forward; } else { motor = forward; brake = back; }

rearWheel1.motorTorque = motor_max motor; rearWheel2.motorTorque = motor_max motor; rearWheel1.brakeTorque = brake_max brake; rearWheel2.brakeTorque = brake_max brake;

frontWheel1.steerAngle = steer_max steer; frontWheel2.steerAngle = steer_max steer; wheelFL.localEulerAngles.y = steer_max steer; wheelFR.localEulerAngles.y = steer_max steer;

wheelFR.Rotate(0, 0, frontWheel1.rpm -6 Time.deltaTime); wheelFL.Rotate(0, 0, frontWheel2.rpm -6 Time.deltaTime); wheelRR.Rotate(0, 0, rearWheel1.rpm -6 Time.deltaTime); wheelRL.Rotate(0, 0, rearWheel2.rpm -6 Time.deltaTime);

}

It's Javascript. And here is the video: http://www.infosecom.net/L200-CD.avi

Sorry by my poor English, it's cuz i'm Brazillian. I'm 13.

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
1
Best Answer

Answer by Uriel_96 · Dec 28, 2010 at 07:08 PM

The problem could be in the axis of the object(you can change the axis)or it could be in the script so Maybe the solution is to change in the script the rotation and put it in a different axis or you just change the axis of the object. how to do this? Very simple, If you have already an empty you only go to the object that has the mesh and rotated and if you dont have an empty you add one and parent the mesh object to the empty and for last move all your script to the empty. The bad thing of this is that you have to change all the parts that says transform to car and put up a variable car.

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
2
Best Answer

Answer by Ejlersen · Dec 28, 2010 at 07:08 PM

Looks great so far, but yeah, the wheels looks a bit funny :)

I can see that you have four lines for the wheels:

wheelFR.Rotate(0, 0, frontWheel1.rpm * -6 * Time.deltaTime);
wheelFL.Rotate(0, 0, frontWheel2.rpm * -6 * Time.deltaTime);
wheelRR.Rotate(0, 0, rearWheel1.rpm * -6 * Time.deltaTime);
wheelRL.Rotate(0, 0, rearWheel2.rpm * -6 * Time.deltaTime);

Instead of setting the z-component, try setting the x-component. That is:

wheelFR.Rotate(frontWheel1.rpm * -6 * Time.deltaTime, 0, 0);
wheelFL.Rotate(frontWheel2.rpm * -6 * Time.deltaTime, 0, 0);
wheelRR.Rotate(rearWheel1.rpm * -6 * Time.deltaTime, 0, 0);
wheelRL.Rotate(rearWheel2.rpm * -6 * Time.deltaTime, 0, 0);

If its still incorrect, then try setting the y-component. Its a bit difficult to give you the correct answer, since I can't see the orientation of the axis :)

And if its still incorrect. Then just keep on asking, we are bound to get it right at some point :)

Comment
Add comment · Show 2 · 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 Henrique Dantas · Dec 28, 2010 at 07:28 PM 0
Share

Oh your answer was more helpful, the problem has been solved! Thank you.

avatar image Ejlersen · Dec 28, 2010 at 07:50 PM 0
Share

Great :) Remember to mark your question as solved, such that people knows that it has been answered ;)

avatar image
-2
Best Answer

Answer by Henrique Dantas · Dec 28, 2010 at 10:44 PM

Thanks to all that answered. Problem Solved :)

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 fireDude67 · Feb 03, 2011 at 03:52 AM 0
Share

Please do not post comments as answers.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Blender wheels wrong rotation 1 Answer

is there a good ai car tutorial about 2 Answers

Connecting steering wheel to front wheels 0 Answers

How to translate car wheels to suspension? 1 Answer

Stuck in Car tutorial - Wheels 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