• 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 Vel_1828 · May 10, 2015 at 11:07 PM · collidertriggerontriggerenterdamage

Area of Damage for a Blink of an Eye

The Topic sums it up. I need to create a spell w$$anonymous$$ch damages everyt$$anonymous$$ng inside of a box Trigger Collider.

In theory, the spell instantiates the Trigger, w$$anonymous$$ch in one frame (optimally) detects all targets inside of it, deals damage to them and as soon as it finished dealing damage - it destroys itself. (the process has to take as little time as possible).

In practice, the OnTriggerEnter bugs out, because the Trigger is there for a fraction of a second and it barely can catch any movement. Yet, it also can't detect if any targets are already inside of it in the moment of it's spawning.

What am I missing? I searched the internets and all I could find were just splinters of informations, useless in t$$anonymous$$s particular context.

Help...?

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

3 Replies

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

Answer by phxvyper · May 11, 2015 at 01:01 AM

I Googled "trigger $$anonymous$$tbox unity activates frame after instantiation," and found t$$anonymous$$s as the first result:

Adding a rigidbody to the explosion prefab has fixed the problem.

Apparently without a rigidbody, a trigger can only detect moving objects.

Source: http://answers.unity3d.com/questions/783803/trigger-instantiated-with-objects-already-inside-o.html

Comment
Add comment · Show 7 · 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 Vel_1828 · May 11, 2015 at 08:08 AM 0
Share

I found that earlier too and added the Kinematoc Rigidbodies to the Trigger and a normal rigidbodies to Targets - still it does not work properly.

After more testingit appears that Targets which are "entirely" inside the Trigger are totally missed - the collisions are only registered, when the Target touches the Trigger's boundaries.

Should OnTriggerStay solve the problem, or will it crunch my entire CPU if there are like 50 Targets inside of a trigger? (a swarm of small targets flying around)

avatar image Vel_1828 · May 11, 2015 at 01:13 PM 0
Share

Anything...? :(

avatar image phxvyper · May 11, 2015 at 11:05 PM 0
Share

Sorry, I was at school.

Heres another technique you could try, without the usage of any hitboxes, in this regard!

In the update function: You can use FindObjectsOfType: http://docs.unity3d.com/ScriptReference/Object.FindObjectsOfType.html to get a list of all of the game objects that are of a specific type (in unity, that means an object that has a certain component script attached).

Search through that list, check to see if your projectile is within a certain distance of one of those players (this is a pseudo-hitbox) then execute whatever code that would normally be executed when that statement is true.

If this technique doesn't fit your requirements, then I'm not sure how to solve your problem.

avatar image Vel_1828 · May 13, 2015 at 12:12 AM 0
Share

Hmm, this looks reasonable, but it would always be a sphere (a distance to any target, checked in any direction - pretty much OvercastSphere :) ) while we need a box to be the boundaries of the spell (The visual effect's restrictions).

Oh well, guess I'll look around more. Thanks anyway for deep reasearch! :)

avatar image barbe63 · May 13, 2015 at 01:33 AM 1
Share

Did you try with OnTriggerStay()?

Show more comments
avatar image
0

Answer by CaKeMeaT · May 10, 2015 at 11:54 PM

Maybe you should keep your colliders active for more than one frame, like two.. And add the the stuff you $$anonymous$$t to a list, after just a few frames you can remove the collided components, and resolve your list so everyt$$anonymous$$ng that was $$anonymous$$t can be handled as a group.

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 Vel_1828 · May 11, 2015 at 08:09 AM 0
Share

Ha, good point! I'm already using a list for storing my Targets which were already hit, but that does not solve the problem with collisions not detecting TriggerEnter event, described in a comment to phxvyper message. :]

avatar image
0

Answer by Eno-Khaon · May 13, 2015 at 02:08 AM

I might be mistaken, but t$$anonymous$$s sounds to me like the scenario where you'd need to be able to read data for nearby applicable targets, w$$anonymous$$ch means either having a huge processing overhead (test all targets in the world for range) or having having a larger memory requirement and constant lesser processing requirements (divide your world into regions and keep track of targets in each region).

Dividing up a world can be done in numerous ways, including (but not limited to) Quadtrees (2-D) and Octrees (3-D), where you have an index for your entire world, divide it in half on each axis, index each of those and note their neighboring regions, divide all of those regions in half, index each of those and note their neighboring regions... and so on down to a minimum physical size and maximum data usage you'd want to utilize.

Then, from there, you'll have subsets in sizes relative to your objectives. For instance, you have that spell blast, w$$anonymous$$ch you know the radius of, check against the region's (and neighboring regions') targets to see what's in range.

$$anonymous$$ed, all of t$$anonymous$$s is intended for larger-scale game environments, but it's still simply one of the ways of keeping track of potential targets when other options are unreliable.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Colliders that do not collide... 1 Answer

Check if something enters my trigget withowt OnTriggerEnter 1 Answer

OnTriggerEnter not being called with multiple colliders 1 Answer

Make object react to certain triggers only 1 Answer

How to not trigger its own collision box? 0 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