• 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 Arookas · Dec 13, 2012 at 07:07 AM · physicsrigidbodycollidermeshstuck

Rigidbody stuck in corners of Mesh Collider

My plan is to have a sort of vertical "tilt the board to get the marble to the bottom" game. The conditions so far are:

  • I have a single mesh collider that doesn't move and a Rigidbody sphere collider.

  • The only thing I ever change is the direction of gravity (which rotates based on mouse position).

  • Also, this is restricted to a XY-plane (2D game).

Mostly, things are smooth, and the physics are great. But if you tilt the board and get the sphere in a corner for too long, it'll be stuck there, no matter where the gravity is rotated afterwards. It doesn't get stuck if the sphere stays in the corner for only a brief moment, though.

My first guess would be to do some kind of "sphere is in the wall" check, but I don't know how I would approach applying the correct force to get it out. As of right now, I do not apply any forces manually on the sphere; PhysX influences the sphere's velocity by itself.

The rotate gravity script is as follows:

 private var baseGravity : Vector3 = Vector3(0.0,-48.0,0.0);
 private var mousePos : Vector2;
 private var rot : float;
 private var rotSpeed : float = 250.0;
 
 function Update ()
 {
     // Get mouse position in screen in range of -1.0/1.0
     mousePos = Vector2(Mathf.Clamp(((Input.mousePosition.x / Screen.width) * 2.0) - 1.0,-1.0,1.0),
                     Mathf.Clamp(((Input.mousePosition.y / Screen.height) * 2.0) - 1.0,-1.0,1.0));

     // Rotate rot by mouse's x
     rot += mousePos.x*rotSpeed*Time.deltaTime;
     
     if (rot > 360.0)
         rot -= 360.0;
     else if (rot < 0.0)
         rot += 360.0;

     // Rotate baseGravity and change physics
     var v = Quaternion.AngleAxis(rot,-Vector3.forward) * baseGravity;
     Physics.gravity = Vector3(v.x,v.y,0.0);
 }

I've tried thus far:

  • Checking/unchecking the "Smooth Sphere Collisions" in the mesh collider.

  • Using standard primitive colliders in replacement of the mesh collider.

  • Every combination of interpolation/collision detection mode on the sphere's rigidbody.

  • Changing the scale of the objects in question (bigger/smaller), gravity speed (less/greater than -9.81), and increasing the speed of physics timesteps

  • Rotating the mesh collider instead of gravity, which leads to a lot more problems than simply rotating gravity (and doesn't actually solve the problem in question).

...amongst other things I probably can't remember. Any ideas would be greatly appreciated!

Comment
Add comment · Show 3
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 gabs · Dec 14, 2012 at 10:01 PM 0
Share

Did you check if the ball's rigidBody is sleeping when that happens? rb.IsSleeping()?

If that's the case, making it unable to sleep may solve this: rb.sleepAngularVelocity = 0f; rb.sleepVelocity = 0f;

avatar image Arookas · Dec 15, 2012 at 04:49 AM 0
Share

Thank you so much! I didn't think to check if it were sleeping; now, it works!

avatar image Antony-Blackett · Jan 07, 2013 at 02:10 AM 0
Share

gabs, you should probably post your comment as an answer. ;P

0 Replies

· Add your reply
  • Sort: 

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

12 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

Related Questions

Is there any way to improve collision detection accuracy with the mesh collider? 2 Answers

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

Why does this MeshCollider think it's half as thick? 2 Answers

When and when not to use kinematic rigidbody? 2 Answers

Do you have to have a rigidbody component for collision detection? 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