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 Tohron · Jan 22, 2014 at 04:28 AM · collisioncollideraoe

Way to Make Multiple Colliders act like Single Collider

There are several enemies in the game I'm making with fairly complicated geometry. Since I'm using mesh colliders (made using meshes imported from Blender), I've had to make them convex for rigidbodies to handle them - which means that I've had to add a bunch of collider-meshes as children of each enemy in order to handle their collision geometry.

This has worked fine for rigidbody work - but it runs in to problems when I start throwing around AoE attacks. A hit to any of the colliders has to register damage, so all of them will register an attack and pass the damage dealt to the central damage-handling script. However, this means that if the AoE (using a SphereCast) hits multiple colliders, all of them register damage. This is a problem, since I want the enemy to only take damage once.

It seems like a solution to my problem would be either to find a way to get all these colliders to behave like they're the same collider, or to find a way to make a complex mesh collider that can have concave geometry while still working with rigidbodies. Any help on either of these routes would be appreciated.

Comment
Add comment · Show 1
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 Benproductions1 · Jan 22, 2014 at 05:00 AM 1
Share

Ins$$anonymous$$d of having your "AOE" "attacks" doing a SphereCast, you could just check yourself for distances to the objects. It might not be as accurate, but it is certainly just as useful and a lot faster.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by nesis · Jan 22, 2014 at 05:22 AM

You need to be more robust in your handling of damage registration. If damaged, record that somehow (eg add the damager to a list of objects that have damaged the character during this frame) in the central damage-handling script, and just reset that record at the start of each frame.

To ensure the record gets reset before trying to do damage in the next frame, you'll need to set your central damage-handling script to be earlier in execution order than the child rigidbody's script, and perform the reset at the start of Update() (or whatever update method you're using).

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 Tohron · Jan 23, 2014 at 04:47 AM 0
Share

So, since it seems there's no simple way to make a concave mesh collider, that leaves me needing a way to separately identify each damage source so as to count it exactly once.

With that in $$anonymous$$d, does Unity let you retrieve something like a hash code for each object? I'd need something like that to make my damage handling more robust, since I'd have to be able to distinguish between two different objects named "ElectroBlast (clone)".

avatar image Benproductions1 · Jan 23, 2014 at 05:02 AM 0
Share

Why not just compare references. It's much cheaper than hashing the object, then comparing that. References are always very cheap.

avatar image Tohron · Jan 23, 2014 at 05:12 AM 0
Share

So how do you compare references? I'm not familiar with the term as you're using it. Thanks!

avatar image Benproductions1 · Jan 23, 2014 at 05:21 AM 0
Share

Lets say you have 2 objects, object 1 and object 2, and at a certain point you reference object 2 somewhere in object 1. At a later point object 1 encounters another object unknown to it. To find out whether that unknown object is in fact object 2, you can compare the reference to the unknown object to that of object 2.

If you don't know what references are and how they are used/created/compared, then you should read up on basic OO.

avatar image nesis · Jan 23, 2014 at 10:05 PM 0
Share

Physics.SpherecastAll will return a list of colliders. You can iterate over that list, and check if the same collider is in it twice by comparing two colliders with ==, just like you would for ints, strings, etc.

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

21 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

Related Questions

Unity2D side collision detection 1 Answer

Object Collision PLEASE HELP!!! 1 Answer

Player shaking when colliding with objects 3 Answers

Collider going through walls with box collider.. 1 Answer

Overlap point of 2 kinematic colliders 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