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 /
avatar image
0
Question by Kiloblargh · Apr 20, 2010 at 07:50 PM · collisionlayersignore

How to set up the CollisionIgnoreManager script to ignore a layer (C# question)

I have two kinds of object that are instantiated together throughout the game, and they must occupy the same space and both collide with the player but not each other. Unity seems to have no automatic way to turn on and off collision between objects by layer or tag or anything- and badly needs this feature- but I found a script to do it, (Thanks, Ryan Scott!) It's C# and I just barely learned JavaScript and don't know how to even edit a C# script.

It says in the docs,

"A simple usage case would be putting various objects onto different layers and using the layer masks for the bitmasks."

But how?

The script as it comes does not expose any variables in the Inspector and appears to declare them all inside functions. What do I need to add to it to make the object it is attached to it ignore collisions with all objects on a layer of my choosing?

Collision Ignore Manager

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Peter G · Apr 20, 2010 at 10:23 PM

Normally, you can just use Physics.IgnoreCollision() to tell Unity to ignore the collision between two objects. The link does that in a more complex way that allows for groups of objects to be ignored.

This link explains how Physics.IgnoreCollision() works. Your code could be something like this.

//This code would go on one of your two spawned objects. //You could insert parts of this into your current code and not have to make twin //variables.

var twin1 : Collider; var twin2 : Collider;

function Start () { twin1 = collider; }

function Update () { Physics.IgnoreCollision(twin1, twin2); }

Comment
Add comment · Show 2 · 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 Kiloblargh · Apr 21, 2010 at 05:34 AM 0
Share

I thought that would work for already existing objects but not for multiple instances of a yet-to-be-spawned prefab.

Actually, I figured out that I can connect one object to the other with a fixed joint, and this will also stop them from trying to collide; and I can do most of the other stuff I need to with triggers.

avatar image Peter G · Apr 21, 2010 at 10:11 PM 0
Share

It works for spawned objects. That's how the FPS tutorial makes sure the rocket's don't collide with the launcher, but glad you solved it on your own.

avatar image
1

Answer by Ryan Scott · Oct 19, 2010 at 01:43 AM

Hi. Sorry I've not been paying attention to Answers.

The script internally calls Physics.IgnoreCollision(). The "Layer" thing I referred to isn't "Layer" in the Unity sense. The integer parameters work as bit masks. Such that each of the 32 bits can be turned on or off to treat objects as groups (this is similar to how unity implements their layers).

(http://en.wikipedia.org/wiki/Mask_(computing) is a fine place to start looking into that if you've not used them before)

To set layer 20, then, you would be able to create a mask by specifying that by: int thisMask = 1 << 20;

To set layers 5 and 20: int thisMask = 1 << 5 | 1 << 20;

In this way the system calls IgnoreCollision on each pair of objects between the groups specified in the masks of each parameter.

There are two primary functions to use: public void addIgnore( Collider newCollider, int thisMask, int mask ) public void addIgnore( Collider newCollider )

The first one takes two masks (specifying one or more groups each) and calls the ignore function appropriately. The second causes the specified collider to ignore all objects in the system.

Hope that answers your question

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

No one has followed this question yet.

Related Questions

Physics.IgnoreLayerCollision - Help 2 Answers

Enable / Disable Layer Collision Matrix thru Script 1 Answer

Layers of collision in Unity (or something similar)? (C#) 1 Answer

revert Physics.IgnoreCollision 2 Answers

Ignore individual collisions between two objects 1 Answer


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