Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by kaini_industries · Sep 26, 2013 at 11:28 PM · collisionrigidbodycollidermeshfixedupdate

Unreliable collision detection between rigidbody and mesh collider

Hi all,

Collisions between my mesh collider and a sphere with a collider and a rigidbody seem to be very unreliable. First off, here's a build of my project:

http://davidmulqueen.kaen.org/Unity/Builds.html

The maze is an FBX imported from 3DS Max, with a mesh collider. It's composed of a 16x16 grid of cubes, attached to each other for the base, and extruded upwards to form the walls. The ball is a Unity sphere with a sphere collider and a rigidbody. My code is in FixedUpdate on the maze, and tilts it (yes, it's horribly inefficient!)...

 #pragma strict
 
 var rotationAmount = 1;
 var xClamp = 30f;
 var yClamp = 30f;
  
 function FixedUpdate()
 {
     
     //rotating the maze
     if(transform.localEulerAngles.x < xClamp ){  
         transform.Rotate (Input.GetAxis("Vertical") * rotationAmount, 0, 0);
     } else if (transform.localEulerAngles.x > (360-xClamp)){  
            transform.Rotate (Input.GetAxis("Vertical") * rotationAmount, 0, 0);
     }  
     
     if(transform.localEulerAngles.z < yClamp ){  
         transform.Rotate (0, 0, Input.GetAxis("Horizontal") * -rotationAmount);           
     } else if (transform.localEulerAngles.z > (360-yClamp)){  
         transform.Rotate (0, 0, Input.GetAxis("Horizontal") * -rotationAmount);           
     }  
 
     //clamp rotation
     if(transform.localEulerAngles.z >= yClamp && transform.localEulerAngles.z < (360-yClamp)){  
         if(transform.localEulerAngles.z < 180){  
             transform.localEulerAngles.z = (yClamp-0.01);  
         } else{  
             transform.localEulerAngles.z = ((360-yClamp)+0.01);  
         }  
     }  
     
     if(transform.localEulerAngles.x >= xClamp && transform.localEulerAngles.x < (360-xClamp)){  
         if(transform.localEulerAngles.x < 180){  
             transform.localEulerAngles.x = (xClamp-0.01);  
         } else{  
             transform.localEulerAngles.x = ((360-xClamp)+0.01);  
         }  
     }
     
     if(transform.localEulerAngles.y != 0){  
         transform.localEulerAngles.y = 0;  
     }
 
     //debug code - detect if nothing is pressed           
     if ((Input.GetAxis("Vertical") == 0) && (Input.GetAxis("Horizontal") == 0)){
         Debug.Log("Nothing is pressed.");
     }
 }
 
 function OnGUI ()
 {
     var xRotation = Mathf.Round(transform.localEulerAngles.x * 10) / 10;
     var zRotation = Mathf.Round(transform.localEulerAngles.z * 10) / 10;
     GUI.Box(Rect(10,10,200,130),"X Rotation:"+xRotation+"\nZ Rotation:"+zRotation);
 }

I've reduced fixed timestep to 0.01, I've made my sphere collider a little smaller than the ball, and still I continue to have collision issues. Any suggestions would be very welcome!

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 Salazar · Oct 05, 2014 at 01:35 PM 0
Share

Same Problem here.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Baste · Oct 05, 2014 at 02:14 PM

Mesh colliders can be a bit tricky. If you can, always use basic colliders instead - they're easier to reason about, less prone to corner cases, and more cost effective. Now, the mesh collider you have on that model should work, but it obviously doesn't. There could be a number of reasons. If you don't have a rigidbody attached to the maze, you should - moving objects needs rigidbodies for their collision detection to work properly. Just make sure to turn gravity off and make it kinematic.

If that doesn't fix it, or you already have a rigidbody attached to the maze, try replacing the mesh collider with box colliders. Simply make a bunch of invisible boxes, give them rigidbodies, and have them match the structure of the maze. Box colliders are faster, and often works better, especially when interacting with mesh colliders, so you might want to do that anyways.

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

17 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to allow collisions on a Child of a Non Kinematic RigidBody ? 1 Answer

Collider going through walls with box collider.. 1 Answer

Rigidbody colliders 1 Answer

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer

Objects with colliders going through walls and each other. 3 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