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 CiberX15 · Aug 07, 2013 at 06:52 PM · collisionparentchild

How to add child collison to parrent object

First Look at the image below:

alt text

I am trying to make a 2D game but I am using 3D collision to keep the player from walking through the "walls." The green box below the hallway is the objects own collision mesh. The two boxes simulating the walls are just cube primitives with their mesh renders turned off and parented to the hallway.

The problem I am running into is that the hallway object has code that tells it how much health it has and how to respond to impacts and such. But when bullets hit the child objects this code is not triggered and the bullets just bounce off because as far as they are concerned they did not hit a valid target.

All I want to do is add those two collision meshes to get that unique shape. If this is not possible I will have to go back and create custom collision models for every hallway which will be a bit of a pain so I am hoping there is just a simple way to combine the collision meshes so the child objects are consider part of the main object and thus when they get hit the parent object runs the relative code.

Thanks in advance for any help.

[Edit]

At this point I have given up and moved on. I just went ahead and made individual models for each hallway type. I then assigned the 3D model the script, and parented the textured flat plane to it. So now the 3D model handles all the physics and code, and the plane just sits there and looks nice.

Still if anyone figures it out post an answer, it will still be quite useful going forward.

Comment
Add comment · Show 3
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 RedCherryStudios · Aug 08, 2013 at 01:39 PM 0
Share

It seems you're using a mesh collider and a box collider. Try removing the box collider?

avatar image CiberX15 · Aug 08, 2013 at 06:06 PM 0
Share

I can do that but I don't see how that would help. The issue is not the collision of the hallway object, that works fine. The problem is that I want to add the collision of the other two objects to the hallway collision so that when they are hit, the hallway registers a hit.

avatar image RedCherryStudios · Aug 08, 2013 at 07:40 PM 0
Share

The only other solution i could think of would be to apply`function OnCollisionEnter(collision : Collision)` to the child object.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Xtro · Aug 08, 2013 at 07:48 PM

In the screenshot, Hallway doesn't have a script for handling the trigger event and it doesn't have a rigidbody (real event receiver) on it. How are you detecting the event on hallway already? If you explain this, we can come to the real question...

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 CiberX15 · Aug 09, 2013 at 12:58 AM 0
Share

Ah, well its sort of backwards from how I described it. The bullet objects are on the highest layer and cast a ray down onto everything below them. When they are over something they have "hit" it. When a bullet hits something it checks if it has a certain script and then calls a "DealDammage()" function on that object. Since the collision objects don't have that script since they are just meant to act as collision for the parent. So when the bullet "hits" them it does not deal damage to the parent as it should.

avatar image Xtro · Aug 09, 2013 at 02:20 PM 0
Share

Hmmm, if you are casting your own collision detection, you have to search for the parent object of the object you've hit.

Actually, I don't know if this behavior is automatic for composite colliders parented by a rigidbody when using regular collision or trigger events.

But anyway, you are not using regular collision. When you hit something with the raycasting, try to search up to the root until you find a parent script object (The object you'll send the dealdamage command)

searching for a parent script:

 // ... your raycast code here
 // "Hit" contains the hit info from the raycast above
 var Transform = Hit.collider.transform;

 // replace your root script with ScriptXXX
 ScriptXXX DetectedParent = null;

 while (Transform){
     var Parent = Transform.parent.GetComponent<ScriptXXX>();
     if (Parent){
         DetectedParent = Parent;
         break;
     }

     Transform = Transform.parent;
 }

 if (DetectedParent) DetectedParent.DealDamage;
 else DoNothing(); // we couldn't find a suitable parent :)

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

16 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

Related Questions

Make a simple tree 1 Answer

How do i kill an "enemy with character controller on + few child objects on" 1 Answer

Getting a Trigger's parent 1 Answer

How to detect collision on child objects from the parent?? 1 Answer

Ragdoll Collisions and Parent-Child Compenent Affect 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