playMaker

Author Topic: How to use collision with GameObject child? [SOLVED]  (Read 17465 times)

amaranth

  • Full Member
  • ***
  • Posts: 172
How to use collision with GameObject child? [SOLVED]
« on: April 02, 2012, 09:41:31 PM »
Does anyone know how to reference a child and then monitor collisions with that child?

I'm using the Get Child state to store the child, but I've not figured out how to check for collisions with the child. It seems like all of the collision events only allow you to use the current FSM owner.

Any advice would be appreciated!

« Last Edit: April 03, 2012, 02:56:04 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: How to use collision with GameObject child?
« Reply #1 on: April 03, 2012, 12:02:53 AM »
This seems to be a fairly common question with Unity:
http://answers.unity3d.com/questions/19992/detect-collision-on-child.html

The PlayMaker equivalent of the OnTouchDelegate in that solution would be to put an FSM on the child that just forwards collision events to the parent.

However, if the parent has a collider, you could use compound colliders:
http://unity3d.com/support/documentation/Components/class-BoxCollider.html (scroll down for Compound Colliders)

Then Get Collision Info should give you the child hit...

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: How to use collision with GameObject child?
« Reply #2 on: April 03, 2012, 02:28:13 PM »
Your information on compound colliders was just what I needed!

Because I'm using Smooth Moves 2D animation, which recreates animation children when you run the game, I can't attach FSMs on animation children. Maybe one day Smooth Moves will allow these, but for now, I have to improvise.

So, this is what I did:
-Trigger event to check for collision with compound collider
-Get Name to check for when the bone inside the animation is hit. (Note to any Smooth Moves people: you have to have collision on the root and the bone.)
-String Compare to see if the bone collider has hit the other object.

Another note:
Because a bone is inside at least two layers of parents, you'll need to use Get Parent at least twice to traverse up to the parent animation.

 




Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: How to use collision with GameObject child? [SOLVED]
« Reply #3 on: April 03, 2012, 02:58:15 PM »
Cool! Thanks for sharing your solution!