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
0
Question by ForrestS · Oct 10, 2013 at 07:53 PM · instantiatecollidersendmessage

New instances of object are colliding when collider is turned off.

My game's player object explodes on collisions with enemies (objects tagged enemy). It sends a message to an object which decrements lives and then instantiates the player prefab. This new player instance is supposed to have an invulnerability period during which the collider turns off, so that it doesn't hit anything until the period is up. The thing is, the new instances are colliding anyway. I've paused midgame to see that the collider is in fact, disabled. not just set to isTrigger, it's disabled totally. I've even tried destroying the collider, to no avail. The object is still colliding. It has 3 children, one of which has a collider that is also disabled (always), and two objects without colliders altogether. If I set the player object that is in the scene to begin with to have that invulnerability period (that is, check a bool newLife to true), it will not collide. it works as intended. It is only new instances that will do this. I'm really unable to figure out why these objects are colliding without colliders.

To be completely clear, during this invulnerability period, the collider is disabled. The box next to it is unchecked. Nothing I do in game, until that period ends, will turn it back on. The object acts as though the collider is enabled anyway, and only new instances do this. The object that exists within the scene on startup works properly.

Any help would be amazing. Thanks.

Comment
Add comment · Show 1
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 Doireth · Oct 10, 2013 at 08:43 PM 0
Share

How exactly are you checking when the player collides with an enemy? In OnTriggerEnter()? onCollisionEnter()?

2 Replies

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

Answer by Doireth · Oct 10, 2013 at 09:15 PM

Why not add a simple flag to determine invulnerability?

 void OnCollisionEnter(Collision col) {
     if(!isInvulnerable) return;
 
     // whatever normally happens during a collision
 }

Whenever you die and respawn, set "isInvulnerable" to true. That way when other collisions occur, they do nothing. To reset "isInVulnerable" try

 IEnumerator ResetInvulnerability() {
    yield return new WaitForSeconds([WHAT EVER AMOUNT TO RESET YOU WANT]);
     isInvulnerable = false;
 }

When you die, start this coroutinue with:

 StartCorouting(ResetInvulnerability());

That will turn off invulnerability after whatever amount of seconds you want so when "OnCollisionEnter" occurs again, normal collisions are calculated.

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 ForrestS · Oct 10, 2013 at 09:39 PM 0
Share

Thanks, this concept is working. I will need to get my enemies to not be destroyed on their collision with the player now while invulnerable, but I can figure that out, I believe. It might be neat to leave it that way too :P

Do you have any idea why my previous method would not work? I'm at a complete loss as to why it was behaving the way it was.

avatar image Doireth · Oct 10, 2013 at 09:49 PM 0
Share

If your object has a rigidbody, the rigidbody counts all children rigidbodies as the same collider creating what is known as a "composite collider". Its possible that your children colliders might have been causing the problem. Honestly, it's been a long of coding and I skipped through most of your post :P

avatar image ForrestS · Oct 10, 2013 at 09:51 PM 0
Share

Hmm that could be it. Glad I got it worked out though, was really slowing me down. Thanks a lot.

avatar image
0

Answer by ForrestS · Oct 10, 2013 at 09:04 PM

I'm using OnCollisionEnter() for all collision stuff. I'll be sure to note that's the case next time.

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

16 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

Related Questions

.sendmessage not working C# 1 Answer

why does Infinite Runner Terrain Collider break my game? 0 Answers

How to Instantiate GameObject on top of collider? (C# 1 Answer

Cannot get collision to do anything 1 Answer

TNT Damage Receiver 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