• 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 pauloefereira · Jun 20, 2011 at 01:09 AM · runtimewheelcollider

Wheel colliders created at runtime strange behavior

Hi there!

Can anyone tell me what's happening with this script? The WheelColliders created starts to move with no torque... I've isolated everything but couldn't find what is wrong.

Thanks in advance!

 class FourWheeledTraction extends MonoBehaviour {
 
 private var wheels = new Array();
 private var wheelColliders = new Array();
 
 private var wheelNames = new Array(
     "frontLeft",
     "frontRight",
     "rearLeft",
     "rearRight"  
 );
 
 private var maxSteer = 25;
 private var forwardFrictionStiffness = 0.02;
 private var sidewaysFrictionStiffness = 0.02;

 var speed = 0.0;
 
 var frontAxisAt = 2.5;
 var rearAxisAt = -2.5;
 
 var frontWheelsRadius = 0.5;
 var rearWheelRadius = 0.5;
 
 var frontWheelsGap = 1.5;
 var rearWheelsGap = 1.5;
 
 public function Start()
 {
     for (i = 0; i < 4; i++) {
         wheel = new GameObject();
         wheel.transform.localPosition = Vector3.zero;
         wheel.name = wheelNames[i];
         wheels.push(wheel);
         wheel.transform.parent = transform;
         wheel.AddComponent(WheelCollider);
         wheelColliders.push(wheel.GetComponent(WheelCollider));
     }
     setupWheels();
 }
 
 public function setupWheels()
 {
     for (i = 0; i < wheels.Count; i++) {
         
         wheelColliders[i].suspensionSpring.spring = rigidbody.mass / 2;
         wheelColliders[i].suspensionSpring.damper = rigidbody.mass * 0.001;
         wheelColliders[i].forwardFriction.stiffness = forwardFrictionStiffness;    
         wheelColliders[i].sidewaysFriction.stiffness = sidewaysFrictionStiffness;
         
         if (wheels[i].name == "frontLeft" || wheels[i].name == "frontRight") {
             wheelColliders[i].radius = frontWheelsRadius;
             if (wheels[i].name == "frontLeft")
                 wheels[i].transform.localPosition = Vector3(-frontWheelsGap, frontWheelsRadius, frontAxisAt);
             else
                 wheels[i].transform.localPosition = Vector3(frontWheelsGap, frontWheelsRadius, frontAxisAt);
             
         } else {
             wheelColliders[i].radius = rearWheelRadius;
             if (wheels[i].name == "rearLeft")
                 wheels[i].transform.localPosition = Vector3(-rearWheelsGap, rearWheelRadius, rearAxisAt);
             else
                 wheels[i].transform.localPosition = Vector3(rearWheelsGap, rearWheelRadius, rearAxisAt);
         }
         
     }
 }
 }

No IDEA! :S

Comment
Add comment · Show 1
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 pauloefereira · Jun 20, 2011 at 01:11 AM 0
Share

Unity version 3.3.0f4

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by pauloefereira · Jun 20, 2011 at 03:19 AM

Yes! Change gameobject parent DOES corrupt data!

 wheel = new GameObject();
 wheel.transform.parent = transform;
 wheel.transform.localPosition = Vector3.zero;
 wheel.name = wheelNames[i];
 wheels.push(wheel);
 wheel.AddComponent(WheelCollider);
 wheelColliders.push(wheel.GetComponent(WheelCollider));
 wheelColliders[i].motorTorque = 0.0;

That solved the problem!

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.

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

1 Person is following this question.

avatar image

Related Questions

Export objects to a .3DS file at runtime 1 Answer

Model building in Unity with primitives and prefabs - opinions desired. 2 Answers

Tracking instantiated objects 1 Answer

prevLayer < state->GetLayer() printed when playing an animation 1 Answer

Examples for realtime moving or hiding of props? 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