Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Werewoodle · Feb 22, 2018 at 09:55 PM · physics2dcollision detectionparent-child

Is it possible to have two 2D colliders touch and then ignore each other while still listening for collisions with other objects?

Say you have a room, with spikes on the walls and ceiling and floor. In that room is a floating object in which its movement is controlled by the player. In that same room there are other objects floating in space.

What I'm trying to accomplish is once the object you control touches a free floating object they stick together and move as one object. At the same time, if any of the single objects in the group touch a spike, it gets destroyed, leaving the other object it was once attached to intact.

I've tried parenting to no success. I'm new to Unity and I'm not a programmer. I'm using Bolt. I understand the basic logic of how things work so I can probably figure out any code you may type. From what I understand all I need to do is get objects to ignore each other once they collide, but only ignore each other and still look for collisions elsewhere. Once they've collided they need to take input from the player as if they were a single object.

The easiest solution would be to just replace the sprite with a new sprite that shows two objects instead of one, but I was hoping to give the player better interactivity by showing a specific object getting destroyed in real time. Thanks. I hope I explained it clearly enough for you.

Comment
Add comment
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

1 Reply

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

Answer by RobAnthem · Feb 22, 2018 at 10:39 PM

Perhaps you are looking for Physics2D.IgnoreCollision? The Physics.IgnoreCollision functions are intended for you to allow two objects to ignore eachother, without it ignoring an entire layer.

Here is the documentation Physics2D.IgnoreCollision Also an example, pulled straight from the docs.

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public Transform bulletPrefab;
     void Start() {
         Transform bullet = Instantiate(bulletPrefab) as Transform;
         Physics2D.IgnoreCollision(bullet.GetComponent<Collider2D>(), GetComponent<Collider2D>());
     }
 }

This makes it so that the instantiated bullet will ignore the object instantiating it, but obviously you can use this is any way you would need.

If you simply want an object to ignore another, and you aren't a programmer, this will do the trick. Attach the script to the object you want to move that has a Collider2D, and drag and drop the object you want to ignore that has a Collider2D into the ignore slot on the inspector.

     using UnityEngine;
     using System.Collections;
     
     public class IgnoreCollider: MonoBehaviour {
         public Collider2D Ignore;
         void Start() {
             Physics2D.IgnoreCollision(GetComponent<Collider2D>(), Ignore);
         }
     }


Comment
Add comment · Show 3 · 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 Werewoodle · Feb 23, 2018 at 02:39 PM 0
Share

Thanks for the effort, but I don't think this will work since IgnoreCollision is not persistent. So if the player were to collide their object with an object and combine them and then collide with yet another object to combine with it wouldn't work. The solution needs to continually add to the list of colliders that ignore each other once they've combined together while remaining active to collide with other objects in the scene.

avatar image RobAnthem Werewoodle · Feb 23, 2018 at 04:01 PM 0
Share

Then what you may be looking for is Physics2D.IgnoreLayerCollision This will allow you to prevent 2 layers from colliding with eachother.

To make it properly work, you would need to setup the layers on the object you want to be collided with only once, and create a secondary layer that is for anti-colliding, then do something like this.

 public int acquiredLayer;
 public int unAcquireLayer;
 void Start()
 {
     Physics2D.IgnoreLayerCollision(acquiredLayer, unAcquireLayer, true);
 }
 void OnCollisionEnter(Collision col)
 {
     if (col.collider.gameObject.layer == unAcquireLayer)
     {
         if (col.collider.gameObject == objectImLookingFor)
         {
             col.collider.gameObject.layer = acquiredLayer;
             //do other logic code here.
         }
     }
 }
avatar image Werewoodle RobAnthem · Feb 23, 2018 at 04:25 PM 0
Share

The collision layers is what I was missing out on. Thanks!

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

78 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

Related Questions

Manual collision detection ? 0 Answers

Instantiate and launch prefab that's overlapping player? 1 Answer

Physics 2D with tile collider corner problem 2 Answers

Hit from kinematic rigidbody2d 1 Answer

Objects on 2D Physic Levels set not to collide still collide. 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