• 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 kop4 · Jun 24, 2011 at 02:25 AM · rigidbodycar

My car is being sporadic...

I had a nice setup with my car working nicely and all,and I saved it and came back and now if the mass of the rigid body is set to more then 100 it starts freakin out with the ground in a way I'm sure you've all experienced. It is pulled into the terrain and is spun around and flung back up into the air. It does the same on a cube or other non-thin object. I am also getting the error:

Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh shapes! Please change mesh geometry or supply a tensor manually!

This might not have anything to do with it, but my car hierarchy is this

Car Assembly (empty object, rigidbody, AND BOX COLLIDER so it should cancel the error)

  • Car model (made of many, many meshes because I used sketchup-bender-unity)

  • Four wheel models

  • Four wheel colliders

And my script is this, if you really want to read through it.

  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 = 40;
  var brake_max = 100;
  var steerSpeed = 50;
  var centerofgravity = -0.5;
   var steer = 0;
   var forward = 0;
   var back = 0;
   var brakeRelease = false;
   var motor = 0;
   var brake = 0;
   var reverse = false;
   var speed = 0;
  function Start() {
  rigidbody.centerOfMass = Vector3(0, centerofgravity, 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;
  if ( steer == 0 && frontWheel1.steerAngle != 0)
  {
      if (Mathf.Abs(frontWheel1.steerAngle) <=

(steerSpeed Time.deltaTime)) { frontWheel1.steerAngle = 0; } else if (frontWheel1.steerAngle > 0) { frontWheel1.steerAngle = frontWheel1.steerAngle - (steerSpeed Time.deltaTime); } else { frontWheel1.steerAngle = frontWheel1.steerAngle + (steerSpeed * Time.deltaTime); } }

  else
  {
      frontWheel1.steerAngle = frontWheel1.steerAngle + (steer *

steerSpeed Time.deltaTime); if (frontWheel1.steerAngle > steer_max) { frontWheel1.steerAngle = steer_max; } if (frontWheel1.steerAngle < -1 steer_max) { frontWheel1.steerAngle = -1 * steer_max; } }

  frontWheel2.steerAngle = frontWheel1.steerAngle;
  wheelFL.localEulerAngles.y = frontWheel1.steerAngle;
  wheelFR.localEulerAngles.y = frontWheel2.steerAngle;
  //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); 
  wheelFR.Rotate(0,0,frontWheel1.rpm * -6 * Time.deltaTime);
  wheelFL.Rotate(0,0,frontWheel1.rpm * -6 * Time.deltaTime); 
  wheelRR.Rotate(0,0,rearWheel1.rpm * -6 * Time.deltaTime);
  wheelRL.Rotate(0,0,rearWheel2.rpm * -6 * Time.deltaTime); 
  }
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
Best Answer

Answer by JonnyHilly · Jun 26, 2011 at 06:37 PM

its probably colliding with itself. Check if you have multiple rigidbodies and colliders on the car intersecting with themselves.

For example did you add seperate objects for doors or wings... that each have physics setup ? if so you might want to disable them until after a crash. I had the same problem you are describing, and it was due to multiple colliding parts, colliding with each other, yet were parented to the car, so they couldn't move how the physics wanted to move/collide them. now I hvae 1 'active' rigidbody, 3 box colliders, 4 wheels.

I dont think the mass is an issue, I use 500 to 1000 on my car masses

its also possible something weird happenned on save. try reimporting the car, or re-loading unity.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Stop Wheel Colliders from flipping over 1 Answer

add force get stronger over time slow. 2 Answers

Mesh Collider Issue 3 Answers

Applying proper drag and center of mass for a vehicle 1 Answer

I do not want to fly a car 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