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 chiggafoo · Jun 23, 2012 at 04:18 AM · physicsrigidbodyobjectoverlap

Stop Rigidbodies From Overlapping

Okay I have a script which allows objects to be moved with the mouse. The objects have rigidbodies and whenever you place an object on another object they can overlap and cause the object to fly everywhere or get stuck. How can i make it so the rigidbodies/collider do not overlap eachother whenever i try to a object inside another objectalt text

Untitled.png (9.6 kB)
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 hijinxbassist · Jun 23, 2012 at 05:16 AM 0
Share

have you tried http://unity3d.com/support/documentation/ScriptReference/Physics.OverlapSphere>OverlapSphere?. This returns true if the sphere radius overlaps another. Ive done this check for spawning with rigidbodies, maybe itll help you in ur current situation

avatar image Fattie · Jun 23, 2012 at 11:21 AM 0
Share

learn about LAYERS

it is a huge innovation Unity3D introduced to solve this sort of problem

avatar image Loius · Jun 24, 2012 at 06:45 PM 0
Share

[collision] Layers make things not collide at all. :p

4 Replies

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

Answer by TomasRiker · Jun 23, 2012 at 07:23 AM

The problem is that all the "static" checks are limited to rays, spheres and capsules and can't do complex shapes. So you have to let pass one frame in order to see if something happened.

Here's my idea:

If the user dragged an object using the mouse or placed an object, mark this object somehow (i.e. set a boolean flag to true). Implement OnCollisionStart for the dragged/newly created object. If this function gets called and your boolean flag is set to true, you know that something "went wrong". If nothing gets called, set the flag to false in the first FixedUpdate.

Now you can detect that a dragged or newly placed object overlaps with some other object. You still have to react to that. A possible way would be to reset both objects' velocity and angular velocity to their old values to prevent them from "exploding" and moving one or both objects along the normal vector of the collision, trying to get them apart.

Comment
Add comment · Show 1 · 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
avatar image chiggafoo · Jun 24, 2012 at 02:26 PM 0
Share

It sorta works, but not real smoothly because sometimes the object will just get stuck in the air not sure why, but then again it'll do. Thanks!

avatar image
1

Answer by Loius · Jun 24, 2012 at 06:44 PM

Move solid rigidbodies by changing their velocity instead of changing their position.

 function Update() {
     ...
     heldObject.rigidbody.velocity = (mousePosition - heldObject.transform.position).normalized * desiredMoveSpeed; 
 }
Comment
Add comment · Show 1 · 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
avatar image chiggafoo · Jun 24, 2012 at 11:52 PM 0
Share

Wow this really just finishes $$anonymous$$asRiker idea! Thanks for the share with combined ideas they fit correctly EXACTLY what i need!! You guys are both right

avatar image
0

Answer by BlacKcuD · Mar 22, 2013 at 12:47 AM

Got to "Edit - Project Settings - Physics" and set the "Min Penetration Penalty" to a ridiculous small number, e.g. 0.001

Comment
Add comment · Show 1 · 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
avatar image Siggytron · Feb 14, 2019 at 02:40 PM 0
Share

If happen to see this, do you know what the fix would be now in 2019? It seems there is no longer a '$$anonymous$$in Penetration Penalty.'

alt text

projsettingsphysics.png (73.8 kB)
avatar image
0

Answer by MHUnity · Nov 17, 2016 at 05:49 PM

Another option can be that you can set your RigidBody collision Detection mode to "Continuous" or "Continuous Dynamic" for fast objects.

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

10 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

Related Questions

How to stop rigidbody.sleep() 2 Answers

Two rigidbody's overlap instead of colliding 1 Answer

swapping out an object on collision 2 Answers

Mesh Overlap causing issues in phsyics engine 1 Answer

Box collider on a moving object-shopping cart 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