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 Sajjoo · Jun 03, 2011 at 02:10 PM · rotatewheelunityiphonebike

Rotate the bike,s wheels to move the bike.

Hi, i am working on a bike racing game and so far i have applied the force on bike to move the bike and used Quaternion and lerp function to tilt and turn the bike. now i want to just apply my force on wheels to rotate them and move my bike like a real bike moves.

can any body please refer me any tutorial or some script or hint to get it on?

P.S i am making this game for iPhone.

thanks.

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
2

Answer by RetepTrun · Jun 03, 2011 at 02:38 PM

This which is complicated http://unity3d.com/support/resources/tutorials/car-tutorial

I used this for a start

http://www.docstoc.com/docs/26688666/Unity3D---Car-Tutorial

When you get to the part where you update the wheel meshes tho I found that there was a bug and the wheels moved to the center of the car. On my car I got rid of that part and then copied it for my own script with the bug fixed. Here it is. Your heirarchy MUST be this for my script and all their centers must be the same, which is best done by some copy-pasting and deleting componets. You have to assign the varibles for the script in the inspector, FR wheel collider is the wheel collider, Fr wheel transform is the wheel's mesh.

My setup must be done for each wheel individually, which means you can have unlimited wheels :-)

vehicle

wheel collider (child of vehicle body)

empty object with the script(child of vehicle body not the wheel collider)

wheel mesh(child of empty with script)


 var FRWheelCollider : WheelCollider;
 
 var FRWheelTransform : Transform;
 
 private var FRWheelRotation : float = 0;
 
 
 function UpdateWheelHeight(wheelTransform : Transform, collider : WheelCollider) 
 {
     var localPosition : Vector3 = wheelTransform.localPosition;
     var hit : WheelHit;
 
     // see if we have contact with ground   
     if (collider.GetGroundHit(hit)) 
     {
         // calculate the distance between current wheel position and hit point, correct
         // wheel position
         
         localPosition.y -= Vector3.Dot(wheelTransform.position - hit.point, transform.up) - collider.radius;
     }
     else 
     {
         // no contact with ground, just extend wheel position with suspension distance
         
        localPosition = Vector3(0,collider.suspensionDistance * -1,0);
     }
     // actually update the position
     wheelTransform.localPosition = localPosition;
 }
 
 function Update() 
 {
     var deltaTime : float = Time.deltaTime;
         
     // calculate the rotation of the wheels
     FRWheelRotation = Mathf.Repeat(FRWheelRotation + deltaTime * FRWheelCollider.rpm * 360.0 / 60.0, 360.0);
 
     // set the rotation of the wheels
     FRWheelTransform.localRotation = Quaternion.Euler(FRWheelRotation, FRWheelCollider.steerAngle, 0.0);
     
     //BLWheelTransform.localRotation = Quaternion.Euler(BLWheelRotation, 0, 0.0);
 
     // now some more difficult stuff: suspension, we have to manually move the wheels up and down
     // depending on the point of impact. As we have to do it twice (two wheels) we put it in a separate function
     UpdateWheelHeight(FRWheelTransform, FRWheelCollider);
     //UpdateWheelHeight(BRWheelTransform, BRWheelCollider);
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Increasing force script, physics and a special 2 wheel Bike setting 0 Answers

Applying colliders on Bike. 3 Answers

Rotate the wheel collider when car flip 1 Answer

Bike/Motobike game 1 Answer

Mesh does not rotate around custom Pivot 1 Answer


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