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 rockyourteeth · Aug 21, 2013 at 04:48 PM · collisioncolliderscaleoncollisionenterlocalscale

How to get expanding object collide when it touches others?

I have an object that is expanding by adding to its localscale each frame. I want it to stop expanding when it hits another collider, but OnCollisionEnter never fires (neither does OnCollisionExit, or OnCollisionStay). How can I tell it to trigger something once it expands to touch another collider?

Here's my script:

 using UnityEngine;
 using System.Collections;
 public class script_blob_player : MonoBehaviour {
     
     private bool touchingSomething = false;

     void Update () {
         if (!touchingSomething)    {    Expand ();    }
     }

     void Expand () {
         float expansionFactor = 1.0f;
         transform.localScale += new Vector3(expansionFactor, 0, expansionFactor) * Time.deltaTime;
     }
     
     void OnCollisionEnter (Collision collision) {
         touchingSomething = true;
     }
 }
 



And yes, my growing object does have a rigid body, which appears to grow as my object grows. And if I turn on gravity so that it falls on another object, the OnCollisionEnter DOES fire. But I'm not using gravity here.

I also found an old similar question that was never answered: http://answers.unity3d.com/questions/142211/detect-collision-between-static-and-expanding-obje.html

Thanks!

Comment
Add comment · Show 3
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 rockyourteeth · Aug 21, 2013 at 07:34 PM 0
Share

They're not spheres; there are various objects.

I'll try the trigger thing and get back to you...

avatar image rockyourteeth · Aug 21, 2013 at 07:44 PM 0
Share

It looks like the trigger DID work. Thanks for the suggestion!

If you copy your "trigger" solution down as an Answer, I'll gladly choose it as the best answer.

avatar image OP_toss · Aug 22, 2013 at 05:24 PM 0
Share

done. Glad it worked!

1 Reply

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

Answer by OP_toss · Aug 21, 2013 at 05:58 PM

Just a thought, but what if you used a Trigger instead of a Collider?

This way it should call OnTriggerEnter when it has expanded enough to tough another collider, and since it's stopping anyways, it shouldn't need to collide with that collider. If it needs collision later, just enable it after the expansion.

You can also do a mathematical approach, by comparing your collider's position and radius to the surrounding colliders' positions and radii. Simple distance math will tell you the exact maximum value you can expand to. This assumes they're both spheres of course...

hope this helps!

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

Resizing an object on collision in unity,Resizing an Object on Collision in unity 1 Answer

OnCollisionStay2D is ignoring OnCollisionEnter2D 2 Answers

Why OnCollisionEnter cannot detect collisions between colliders? 1 Answer

Check if collider is colliding with anything non specific? 1 Answer

how to PlayOneShot from a OnCollisionEnter wiith a RaycastHit /Collider>Raycast 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