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 macmouse · Jan 14, 2015 at 03:10 PM · movementdestroydirectionattract

Two Objects - Contraction?

I have two objects. One sphere is moving left and one sphere is moving right. Now, when they're too close (when colliders touching), they should contracted and destroyed.

How can I solve this?

alt text

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

Answer by MakinStuffLookGood · Jan 14, 2015 at 04:12 PM

There are many ways to do this. I believe you mean "collision" as opposed to "contraction".

Simplest way would be something like:

 void OnTriggerEnter (Collider col)
 {
     // Do some check here to make sure it's the object we want to destroy on
     if (someCheck)
     {
         Destroy(gameObject);
     }
 }

We'd need more information about the exact behaviour you want.

Really you should just look up collision detection. There are lots of official resources on the Unity website. Start here: http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers

You may find it helpful to do some more intro tutorials before asking more questions on forums like this.

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 macmouse · Jan 14, 2015 at 04:57 PM 0
Share

When the two white spheres touching each other, then they will be destroyed. When the two green (colliders) touched, then the two objects contracted and then when the two white spheres touch together, they will be destroyed.

avatar image MakinStuffLookGood · Jan 14, 2015 at 05:55 PM 0
Share

Ahhh gotcha. So when the objects are in range, they should pull towards one another.

Take a look at OnTriggerStay. What you can do is have a force constantly applied to the objects velocity in the direction B-A (where A is the object detecting the trigger and B is the triggering object). You have that code on the larger trigger spheres, and then the destruction on collision code on the spheres themselves. Shouldn't be too complicated, but let me know if you run into any issues.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I keep my character facing the direction of travel after movement stops? 1 Answer

Tracking HTC Vive Controller Motion Direction? 1 Answer

Need player to walk in random direction 2 Answers

4 way direction movement using a Character Controller. 1 Answer

Character rotating to previous rotation 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