playMaker

Author Topic: Wrong Trigger Triggering FSM Event[SOLVED]  (Read 1442 times)

acornbringer

  • Junior Playmaker
  • **
  • Posts: 75
    • Acornbringer.com
Wrong Trigger Triggering FSM Event[SOLVED]
« on: August 12, 2019, 04:51:47 PM »
Hello,

I have an enemy character in my scene with a capsule collider for its body and a separate "pyramid" shape collider coming out of its head for the field of view. When I throw a punch at the enemy, I create a trigger cube so if there's an enemy inside the cube, I can deal the enemy damage and play an animation to show it's been hit.

The issue is when my attacks intersect with the vision pyramid, it triggers the event as if I hit the character itself!

Here's a video I made to hopefully make this clearer:


I thought that because the vision cone was a child of character with the capsule collider on it, that some how Unity was calling them the same trigger. However I made a mock-up with only cubes in the same hierarchical arrangement and the triggers were working as expected.

If you think you might know what's going on here, I would love to hear from you!

--

Something I noticed as well that I hadn't seen before was on the enemy character, inside the scene, I can see a "Play Maker Trigger Enter (Script)" Component that I have never seen before. I saw that it was some kind of Unity bug exposing hidden components but maybe it has something to do with my issue.

And maybe something else to note is that when I un-parent the vision pyramid from the character, it no longer sends the event when I attack it.

Thanks!

« Last Edit: August 13, 2019, 02:09:35 AM by jeanfabre »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Wrong Trigger Triggering FSM Event
« Reply #1 on: August 13, 2019, 12:14:45 AM »
OK so this is easy to fix. Good to learn it now, because it won't be the last time you need this kind of solution:

Unity has 'Layers' for objects. You can create a new layer, then assign any game object to a layer.

1) Create/set a layer for the trigger you want to hit for damage
2) Create/set a layer for the cube punch trigger
3) Go to Edit -> Project Settings -> Physics
4) In there you will see a 'Layer Collision Matrix', with a set of ticks. You have the layers along the top, as well as going down the left. It shows how each layer interacts (or not) with each other. A tick means they can touch each other, where as the absense of a tick means that (even with colliders, etc) they will ghost through each other and not register.

So to just sum up a bit; what you are doing is placing the key parts in specific layers, then telling them to only interact with the layers they need to. This will mean that your cube will ghost right through the cone and not register the collision/trigger.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Wrong Trigger Triggering FSM Event[SOLVED]
« Reply #2 on: August 13, 2019, 06:40:01 AM »
Hi.
Just a warning : layer is limited to 32

acornbringer

  • Junior Playmaker
  • **
  • Posts: 75
    • Acornbringer.com
Re: Wrong Trigger Triggering FSM Event
« Reply #3 on: August 13, 2019, 08:06:47 AM »
[...]
Unity has 'Layers' for objects. You can create a new layer, then assign any game object to a layer.
[...]

Worked perfectly! Thanks for pointing that out to me. I can already see using layers coming in handy as I continue with this project.

Hi.
Just a warning : layer is limited to 32

Good call. Thanks!