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 JVILL · Jan 30, 2013 at 09:36 AM · collisioncollidertriggerboxempty

Simple Colliders Question

I'm new to colliders and I'm having trouble getting them to work.

I have an empty game object with a box-collider component. It is parented to a player controller and therefore follows them around.

There are other empty game objects through the scene with box-collider components attached. They are static (not moving) and so a rigid body cannot be added to them.

I want to detect when the player-attached collider and the world colliders collide.

Note: Because I thought my terrain colliders (among others) might get in the way, I thought of suspending these other colliders 100m in the air along with the parented one.

I have tried using onCollisionEnter, but can't seem to get it to work. I've tried different combinations of 'is trigger' as well. Please help!

Which one is the trigger? Which one should have the script attached? What should the script look like? Do either of them NEED to be tagged? :(

EDIT: ALSO! Please note I've considered using Vector distance, and when the distance between the two objects is less than a certain distance I could trigger the event that way, but there will be thousands of these floating game objects, and vector distance would probably use more processing power than onCollisionEnter + Exit... or would it?

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 Berenger · Jan 30, 2013 at 09:50 AM

A collision event between two colliders is raised only if the movement was made by the physic engine, like the gravity on a rigidbody. In your case, parenting is moving that empty game object. You need to add the collider on your player.

Or, there is the kinematic notion. Set a rigidbody on that empty game object, child of the player, with a box collider. The rigidboy must be kinematic, without gravity, and frozen on everything. Set the collider as trigger, and you'll get the OnTriggerXXX events.

Comment
Add comment · Show 5 · 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 JVILL · Jan 30, 2013 at 10:08 AM 0
Share

Thanks! It was detected! Sadly, however, when I tried switching the roles so that the one with the Rigid body was stationary and the one without was moving, it didn't work. That's okay though, I think I'll be able to make this work. :)

Quick follow up question: Now that the two have collided, how do I get the transform position of the object I collided with? (note: not the actual collision location)

avatar image JVILL · Jan 30, 2013 at 10:36 AM 0
Share

Never$$anonymous$$d! Solved it with this:

 r = other.transform.position.x;
 c = other.transform.position.z;
 Instantiate (fLow1, Vector3(r, 0, c), transform.rotation);

Next, however, I need onTriggerExit to destroy just that object that was instantiated. I tried:

 function OnTriggerExit ( other : Collider )
 {
     Destroy ( other );
     
 }

But, alas, no luck.

avatar image JVILL · Jan 30, 2013 at 10:38 AM 0
Share

Just realised the above code is destroying the box collider and not the Instantiated object. Gah! Assigning a name to the instantiated object is infeasible because there will thousands of them, many of them clones.

avatar image JVILL · Jan 30, 2013 at 12:19 PM 0
Share

Follow-up question continued at: http://answers.unity3d.com/questions/390503/remove-object-based-on-its-position-alone.html

avatar image Berenger · Jan 30, 2013 at 12:31 PM 1
Share

Destroy ( other.gameObject );, if you want to destroy the object entirely.

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

10 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

Related Questions

Extracting child trigger from compound collision 0 Answers

Box Trigger and Mesh Collider on one object. 1 Answer

Using shadows as Triggers? 1 Answer

How to restart scene with trigger? 1 Answer

Collider won't collide with a trigger 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