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 SanderN · Mar 09, 2015 at 08:17 AM · physicsrigidbodyignoreanother

Rigidbody Ignore another Rigidbody?

Hello! So I have an interesting questions- Is it possible and how to make it so 2 rigidbodys Ignore each others physics?

Basically I have rigidbody A and rigidbody B and I want to make it so that they don't affect each others position. I still want them to collide with each other but I don't want them to be moved by one another. Yes, I could change the mass of rigidbody A and make it higher but then rigidbody A wouldn't be affected by rigidbody B but Rigidbody B would still be affected by rigidbody A.

Anyway long story short- How to make 2 rigidbodies ignore each others rigidbodies but still register each others colliders like when a rigidbody hits a rigidbody it acts as the other rigidbody is a collider instead of a rigidbody?

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 SanderN · Mar 09, 2015 at 08:22 PM 0
Share

I have been all over the internet and haven't found a solution. I have no idea how to make this work.

5 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by DocMcShot · Mar 09, 2015 at 08:47 PM

Yes. You should be able to write 2 scripts and attach one to each of the objects. It really depends on what you want to happen if the 2 objects do collide. Do you want them to just immediately stop moving? Do you want the objects to be able to pass through each other? What are you wanting to do? If you want them to immediately stop you could do something like this:

Object 1 Script:

 void OnCollisionEnter(Collision other)
 {
    if(other.gameobject.name == "myFirstGameobject")
    {
       gameObject.rigidbody.velocity = Velocity.zero;
       gameObject.rigidbody.angularVelocity = Velocity.zero;
       // You may also want to use the function:
       // gameObject.rigidbody.Sleep();
    }

then on your second GameObject attach a script like:

     void OnCollisionEnter(Collision other)
     {
        if(other.gameobject.name == "mySecondGameobject")
        {
           gameObject.rigidbody.velocity = Velocity.Zero;
           gameObject.rigidbody.angularVelocity = Velocity.Zero;
           // You may also want to use the function:
           // gameObject.rigidbody.Sleep();
        }


Another good solution (depending on what you are trying to do) may be using the Layer Based Collision. See the Unity Manual to use it. Here is the link to it. http://docs.unity3d.com/Manual/LayerBasedCollision.html

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 SanderN · Mar 09, 2015 at 09:58 PM 0
Share

Basically I just need them to collide with each other but not move each other. Like if Rigidbody A flies into Rigidbody B, I don't want Rigidbody B to move, what I need is Rigidbody A to act like Rigidbody B is a collider ins$$anonymous$$d of rigidbody and same when Rigidbody B flies into Rigidbody A.

So it's like LayerdBasedCollision but ins$$anonymous$$d of ignoring collisions I need them to ignore rigidbodies.

Also I tried the scripts but they didn't seem to work, they had few errors that I fixed but they didn't seem to do anything.

Now I actually did find some kind of a solution that involves LayerBasedCollision. It's a little "sloppy" but it seems to work more or less. Basically both rigidbodies have a child object that has $$anonymous$$inematic rigidbody attached to them and has a collider that's slightly bigger radius than the parent collider and I made it so Parent and Child colliders ignore each other.

So long story short- now both Objects carry around extra colliders that stops their rigidbodies from colliding, so it's like a wall between 2 rigidbodies atm to stop them from affecting each other. But like I said it's a little sloppy atm and if possible I would like to see someone come up with better solution than this.

avatar image
1

Answer by alok-kr-029 · Mar 09, 2015 at 09:09 AM

you can check the istrigger component in its collider in inspector by this you can check if they trigger each other and they will not effect its position

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 SanderN · Mar 09, 2015 at 09:23 AM 0
Share

Ok tried it but what it seemed to do is ignore every collision in the scene which is exactly opposite what I need. I need it to still collide with everything in the scene.

avatar image
0

Answer by wahaca · Jan 16, 2017 at 03:05 PM

Maybe put them in two different layers and use Layer Based Collision Detection: https://docs.unity3d.com/Manual/LayerBasedCollision.html

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

Answer by Alverik · Mar 28, 2020 at 07:45 AM

Physics.IgnoreCollision(collider 1, collider 2, true);

or false if you want to revert it.

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

Answer by bisdaeas · Mar 28, 2020 at 09:16 AM

You can use unity's built in matrix system that allows you to chose what layers can interact with others.Official Site

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

26 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

Related Questions

Is it possible to get the physics engine to ignore calculating a rigidbody? 1 Answer

Player Pushes Enemies. (That's bad) -Still Unanswered- 1 Answer

How do I connect multiple spheres using joints and make a character? 1 Answer

Shooting a cannonball. 6 Answers

Solar System Simulator Orbits Not Working 2 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