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 ShiftedClock · Aug 09, 2013 at 09:57 PM · collisionphysicscoroutineoncollisionenter

Changing transform.localScale but OnCollisionEnter isn't executed

Hi, I've tried to make the description of my problem as clear as possible, but if there's any more information you'd like, please ask. The setup:

I have a Grenade GameObject with a script DetonateAfterDelay.cs on it that causes it to destroy itself and spawn a GrenadeExplosion object. The GrenadeExplosion object has two scripts on it, ExpandAndDie.cs and AddForceOnCollision.cs.

Here are the two scripts on the GrenadeExplosion object:

http://pastebin.com/aizuL7TJ

The ExpandAndDie script uses a coroutine to Lerp the transform.localScale over about 0.15 seconds, effectively making the GrenadeExplosion a rapidly expanding sphere. It looks very simple and nice. :)

The Player has a CapsuleCollider and Rigidbody attached. The GrenadeExplosion has a SphereCollider.

The trouble is that the GrenadeExplosion object only registers a collision with my Player object when the Player is moving. When the Player is standing still, the explosion object passes through the Player and does not trigger the OnCollisionEnter code found in the AddForceOnCollision script. In fact, even the Debug.Log statements I have in that script do not trigger.

I don't know why this is the case, but I think it might have something to do with how I change the GrenadeExplosion object's localScale.

Perhaps using a coroutine (GrowAndDie()) is part of the problem? But I can't figure out a way to solve this problem without using a coroutine.

Do I need to use an animation to expand the sphere for the OnCollisionEnter script to work properly? I'm in the process of trying this method, but I don't know if it will solve the problem, and it's proving more complicated than I expected. I would prefer to stick with the simple procedural method of lerping localScale, if possible.

Any help, advice or direction is greatly appreciated. Thanks.

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

1 Reply

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

Answer by LucTremblay · Aug 10, 2013 at 01:12 AM

At a gance, this might be caused by an optimization of the physics system, where un-moving rigidbodies are not tested together. I think that scaling the root of the rigidbody does not provoke a 'movement', and therefore the collision checks are not being done. Scale and physics rarely get along in game engines :)

Try

 rigidbody.WakeUp();

right before your yield.

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 ShiftedClock · Aug 10, 2013 at 02:44 AM 1
Share

wesome, thanks, that worked. I'm going to keep playing around, because I think there must be a way to set things up that makes the WakeUp call unnecessary. Thanks again.

avatar image LucTremblay · Aug 10, 2013 at 03:54 AM 0
Share

For what it's worth, I'm pretty sure scaling as you do is a special case of the physics engine, and WakeUp was expressedly made for that kind of situation. I can't think of a cleaner alternative, other than doing your own collision checks.

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

15 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

Related Questions

How to end a coroutine early 0 Answers

OnCollisionEnter event seems to be called late. 3 Answers

OnCollisionEnter called once even with multiple contacts 1 Answer

OnCollisionEnter inside FixedUpdate? 1 Answer

Collision Query 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