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 /
  • Help Room /
avatar image
0
Question by twotostudio · Sep 16, 2020 at 09:45 AM · collisionphysicsrigidbodystack

How do I prevent stacked objects from being spoiled by collisions?

I have objects falling from different positions. And they form a stacked tower. When the tower is extended, it may hit objects that we missed from other positions. In this case, the objects in the tower should not move and the objects hit by the tower should move. I've tried a lot of code found at the bottom as comment lines. However, different problems arise in all of them. The tower formed by the objects that make the desired collisions must be able to remain stable. How can I do what I want?alt text

ekran-alıntısı.png (45.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 streeetwalker · Sep 16, 2020 at 11:38 AM 0
Share

@dadaygames, to me it's not clear in your description what you want exactly. Can you provide diagrams and/or video of the behavior as it is now (that you don't want) and the behavior you do want?

avatar image twotostudio streeetwalker · Sep 16, 2020 at 01:01 PM 0
Share

alt text

whatsapp-image-2020-09-16-at-155837.jpeg (81.4 kB)
avatar image twotostudio twotostudio · Sep 16, 2020 at 01:02 PM 0
Share

I tried to explain by drawing I hope it was. $$anonymous$$y goal is to push the objects hit by the tower from the side when the character moves. And the tower remains stable.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by streeetwalker · Sep 16, 2020 at 02:22 PM

If I understand your diagram, I think what is happening now essentially how physical objects behave in the real world - is that your sense?

What you want is for the tower to impervious to all collisions?

If you have a Rigidbody and a collider attached to an object, it will react with equal and opposite force to a collision where the forces have been applied through the physics engine. This is called collision resolution. If you remove or disable the Rigidbody component, the collision resolution forces will not be calculated on the object.

So I believe that is what you need to do as each piece settles on the tower, disable or remove its Rigidbody component.

That may present other problems. For example, if you are using the physics system to add forces to move the whole tower, you'll need to find another way of doing that.

Comment
Add comment · Show 9 · 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 twotostudio · Sep 16, 2020 at 02:53 PM 0
Share

When the rigidbody disappears, the objects do not stay on top of each other, but begin to intertwine.

avatar image streeetwalker twotostudio · Sep 16, 2020 at 03:15 PM 0
Share

then you must have something else going on.

I just ran a test on cubes that drop on top of each other, and destroying the Rigidbody does not alter their position in anyway - they remain frozen in the position they are in at the time the Rigidbody is removed. So we have to see what else is going on in your code.

Here is my sample code:

     public class TestRemovRB : $$anonymous$$onoBehaviour {
         public GameObject[] cubesRB;
     
         void On$$anonymous$$ouseDown() {
             for( int i = 0; i < cubesRB.Length; i++ ) {
                 Destroy( cubesRB[i].GetComponent<Rigidbody>() );
             }
         }
     }



So how are you removing/disabling the Rigidbody?

avatar image twotostudio · Sep 16, 2020 at 04:04 PM 0
Share

That's all the code that affects the physics of objects. I destroy rigidbody this way. What kind of error could there be in these codes?alt text

ekran-alıntısı.png (21.5 kB)
avatar image twotostudio twotostudio · Sep 16, 2020 at 04:08 PM 0
Share

these codes are inside the 3 types of spawn objects.

avatar image twotostudio · Sep 16, 2020 at 04:11 PM 0
Share

And the objects are intertwined in this way. Could there be a problem with the physics settings in another section?

alt text

3.png (38.2 kB)
avatar image streeetwalker twotostudio · Sep 16, 2020 at 04:27 PM 0
Share

I have experience with this recently. What I discovered was this:

At the time OnCollisionEnter runs, the collision resolution forces have been calculated, but the collision cannot be completely considered completely resolved, in sense, until the objects come to a rest. It may take many FixedUpdate frames for that to happen, depending on how hard objects hit each other.

When two objects hit, they may penetrate each other if they are moving fast enough. I think in your case what a happens is they are penetrating at the time OnColllisionEnter is called, and you are removing their Rigidbodies at that time, freezing them in those positions.

In my case, the easy solution was to wait for enough FixedUpdate frames for the objects to move to their resting positions, and then destroy their Rigidbodies. But this is not really a neat solution.

I think a better, more perfect solution is for you to calculate where their resting positions should be, destroy the Rigidbody, and then use their transforms to position them in their perfect resting positions that you calculated.

avatar image twotostudio streeetwalker · Sep 16, 2020 at 04:37 PM 0
Share

How can I calculate resting positions. $$anonymous$$y objects with 3 different y sizes are co$$anonymous$$g up randomly. I don't know if I fully understand what you said, but as far as I understand it doesn't seem possible.

Show more comments
avatar image
0

Answer by twotostudio · Sep 16, 2020 at 04:49 PM

I did continious instead of discrete in collision detection in rigidbody settings. And I guess they don't intertwine anymore.

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

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

Related Questions

How to make rigidbody static ? 0 Answers

Sphere bouncing back on edges of aligned objects 0 Answers

2D RigidBody slightly penetrates objects causing a bounce effect. 3 Answers

Ball passes through the floor on movement 1 Answer

What's the best way to get clean, smooth collision physics? 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