• 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 Toxast · Sep 09, 2012 at 01:11 PM · collisions

Dynamic collision layers

I am writing a simple towerDefence game. There are a lot of ghost mobs and rockets, both spawning and flying around. Ghost mobs sometimes turn from spirits to fleshy and conversely.
I want rockets to move through them in spirit mode and collide when they are fleshy.

I thought it can be achieved via collision layers, but it seems that they cannot be dynamically changed through scripting.

Now i am just searching for elegant solution, that dont suggest counting every rocket and making IgnoreCollision on them for each mob.

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
10

Answer by aldonaletto · Sep 09, 2012 at 01:39 PM

Layers are the best solution. You don't need to redefine the layer matrix at runtime - simply change the mob's layer from default to a specially created ghost layer depending on its state, and let the missiles in a missile layer, which doesn't collide with ghost. Supposing that you've created the ghost layer (menu Edit/Project Settings/Tags) in layer 8, control the mob's layer like this:

  if (ghostMode){ 
    gameObject.layer = 8; // move to ghost layer
  } else { 
    gameObject.layer = 0; // move to regular layer
  }
NOTE: Remember to create also the missile layer, and to configure the Collision Matrix in the Physics Manager (menu Edit/Project Settings/Physics) so that objects in ghost don't collide with missile.
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 Toxast · Sep 10, 2012 at 11:18 AM 0
Share

Thanks a lot, that is very helpful =)

avatar image Fattie · Sep 10, 2012 at 12:50 PM 0
Share

toxa, be sure to Tick a useful answer, to keep the board tidy ! good luck

avatar image Nuntis · Jan 18, 2020 at 09:31 PM 0
Share

Thank you so much for this solution I can't tell you how much this has been racking my brain as I have multiple layers I wanted to change interactions with through input and thanks to you it's possible. I honestly can't rate you enough

avatar image
0

Answer by Headworker · Sep 09, 2012 at 02:18 PM

I am no expert, but what about replacing them on the change event? Afaik all object can be deleted and replaced with another object, which can inherit values from the former (like position, health and so on...)

This way it would certainly be possible to have different impact or collision events.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 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

Related Questions

Checking Child collisions through parents 1 Answer

Collision angle of collided 1 Answer

iOS Rididbody Collisions 0 Answers

2D platformer levers and moving platforms question. 0 Answers

Applying a force to multiple rigidbodies at once. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges