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 KEMBL · Aug 01, 2013 at 09:54 AM · collisiontriggerspawnspawning

Trigger or Colission not work if inside volume

Hello, there!

I found that OnTriggerEnter/Stay/Exit and OnColissionEnter/Stay/Exit not work when object1 instantiated inside collider of object2. When its colliders not intersect on spawn moment all works great. Easy to understand why :)

The only way to check if one object still near to spawned point is Vector3.SqrMagnitude(pos1,pos2). Not bad, but this need Update() :(

Any other way to solve this problem with triggers?

For now I create several colliders on spawn point, when new object appear and start move it will intersect with one of those volumes. But ... if object has great size, it intersects with all colliders at once and this approach not work universally :)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by TonyLi · Aug 01, 2013 at 02:52 PM

Use OnTriggerStay or OnCollisionStay. This is called every fixed update that the colliders are in contact. At least one needs a [non-kinematic - or kinematic] rigidbody. OnTriggerStay is less efficient than OnTriggerEnter, of course, because it runs every fixed update instead of just once.

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 KEMBL · Aug 02, 2013 at 07:32 AM 0
Share

Thank you for answer, you right in theory, but on practice things little complicated. System will work ONLY if object, which emitted in trigger volume, has Rigidbody.You cannot add trigger AND rigidbody to emitter, and wait while emitted object with collider produce any callback, it will not. This situation very not optimal, it demand to produce crowd objects with rigidbody. Am I clear?

avatar image TonyLi · Aug 02, 2013 at 01:33 PM 0
Share

I've done this in practice and it works fine. $$anonymous$$y triggers were static colliders. The spawned object was mobile and had a kinematic rigidbody. Sorry, I mis-wrote when I said "non-kinematic rigidbody" earlier. Give it a try.

avatar image KEMBL · Aug 02, 2013 at 05:45 PM 0
Share

" spawned object was mobile and had a kinematic rigidbody" - yes, this is the only way. You cannot add rigid to static collider, you need to spawn many objects with rigidbody, which in my situation not needed for any other reason in scene. This is the thing which I said as not optimal earlier.

avatar image TonyLi · Aug 02, 2013 at 08:09 PM 0
Share

So neither object ever moves? If either object moves, it shouldn't be a static collider (or it should have a rigidbody).

avatar image KEMBL · Aug 03, 2013 at 12:44 PM 0
Share

Emitter is static and emitted objects is navmesh agents which immediately start move to its targets. For now I solve problem with simple check the distance and start spawn next object only when distance is greater than some value.

avatar image
1

Answer by Jamora · Aug 02, 2013 at 08:32 PM

You could possibly use the Bounds of your colliders. Whenever you need to check if it's inside your triggers, you just use collider.bounds.Intersects(otherBound) You will only need two objects with colliders. No rigidbodies are needed if that is a problem for any reason.

Comment
Add comment · Show 1 · 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 KEMBL · Aug 03, 2013 at 12:41 PM 0
Share

Thank you, Jamora, this approach also require Update(), but looks more accurate than my distance checking! I'll keep your idea in memory and try it when I will need more accurate results )

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

17 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 avatar image

Related Questions

Trigger Spawning? 1 Answer

Do triggers not fire if spawned colliding? 1 Answer

onCollisionEnter2d spawn - unity 4.6 0 Answers

Collision problem when spawning in the collider 1 Answer

Spawning explosions and detecting objects in range 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