• 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 Goody! · Dec 26, 2009 at 03:31 AM · collisionphysics

What is the most efficient way to have a rigid body object ignore all collisions except with one thing?

Hello and Happy Holidays!

I have objects that need to have a rigid body to interact with 1*one*1 thing in the game but I don't want them colliding with anything else. I know about find object with tag but that seems silly and inefficient to define each and every other class of game object in that way. For example...

    var bub0Ref = GameObject.FindGameObjectsWithTag("Bub0");
var bub1Ref = GameObject.FindGameObjectsWithTag("Bub1");
var bub2Ref = GameObject.FindGameObjectsWithTag("Bub2");
var bub3Ref = GameObject.FindGameObjectsWithTag("Bub3");

PLUS... in my game different GO's are instantiated at random times and having to call find objects"..." over and over again to make sure that none of them are slipping by (and causing collisions) rankles me.

I saw the collision manager on the wiki but it's done in c# and I've been strictly JavaScript. Is there a javascript version somewhere?

I've also seen other responses about using classes but they were a bit over my head.

Can I do it with a layermask? Or can one GO have multiple tags somehow to put similar if not identical things into a class of object?

Any help is appreciated!

It's Christmas day! --Goody!

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
Best Answer

Answer by jashan · Dec 26, 2009 at 10:58 AM

In my experience, in a client-server-based game where I need to disable all collisions between game groups (groups of people who may be playing in the same level but who must not interact in any way with the players of the other groups), this is not a problem performance-wise.

I have a CollisionManager that calls Physics.IgnoreCollision in both directions for each object that already exists whenever a new object is instantiated. However, I have my own book-keeping which is based on Lists: Each game group has a list of players to which the relevant game objects are attached in lists; that way I have very fine control over who can interact with whom. That fine-grained control is useful for a lot of other things, too, so I don't only have that for my collision management.

Here's an example method from my CollisionManager (I'm calling this whenever a new "wall" is created which happens whenever a player makes a turn, so that's quite frequent; especially when there's a lot of player on the server); it's in C# but should be easy enough to understand and convert to JavaScript:

public void IgnoreWallCollisions(Collider currentWallCollider) {
    foreach (GameGroupData otherGameGroup in GameManager.Instance) {
        if (otherGameGroup != this.gameGroup && otherGameGroup.Level.IsPlaying) { // look at all except for myself...
            foreach (TeamData team in otherGameGroup) {
                foreach (PlayerData player in team.TeamMembers) {
                    if (player.IsAlive && player.CycleParameters != null && player.CycleParameters.collider != null) {
                        Physics.IgnoreCollision(player.CycleParameters.collider, currentWallCollider, true);
                        Physics.IgnoreCollision(currentWallCollider, player.CycleParameters.collider, true);
                        foreach (Projectile projectile in player.Projectiles) {
                            if (projectile != null && projectile.collider != null) {
                                log.DebugFormat("Ignoring projectile-wall collisions between: {0} and {1}", projectile.gameObject.name, currentWallCollider.name);
                                Physics.IgnoreCollision(projectile.collider, currentWallCollider, true);
                                Physics.IgnoreCollision(currentWallCollider, projectile.collider, true);
                            }
                        }
                    }
                }
            }
        }
    }
}

You may consider voting up Physics: Layer based Ignore Collision as this might help simplify things for you a little bit.

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 Ashkan_gc · Dec 26, 2009 at 08:19 AM

there is not any simple way to do this in unity now. you should find all gameobjects that you want to ignore collisions with them and call the Physics.IgnoreCollision method for them. but for having a list of gameobjects you can put a reference from each game object in to a list in it's creation time. use a List. i don't know if you can use generics in current js compiler or not. sorry

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to use Physics.IgnoreCollision for multiple objects / toggling collisions for multiple, specific objects? 0 Answers

Having more than one collider in a GameObject? 8 Answers

Changing mesh collider's mesh cause objects go into mesh. 1 Answer

Rigidbody necessary to use collision detection 1 Answer

How can I make two Character Controllers Collide 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