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 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
11

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.

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

Different particles for different collisions. 1 Answer

Elastic Collisions with Rigidbodies 1 Answer

Check collisions with more than one enemy? 1 Answer

WheelCollide GetGroundHit falling behind? 0 Answers

collision sounds 3 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