playMaker

Author Topic: Trigger enter not working! Help!  (Read 20517 times)

ryf9059

  • Full Member
  • ***
  • Posts: 100
Trigger enter not working! Help!
« on: September 03, 2013, 03:31:29 PM »
Following what Jean suggests in this link (http://hutonggames.com/playmakerforum/index.php?topic=4177.0), I'm trying to get the object fsm name so I can identify the type of object collided with my trigger.

(If you think the link is too long and didn't read it. here is basic: I'm trying to identify when two object collides, what's the type of a object that hits the other. But it's better you read it.)

To do so, I added a trigger enter global event to my enemy fsm. When the event triggers, it will check what object hits this trigger. I used Get Trigger Info action and stored the Game Object Hit in a GameObject. But here the problem comes: when I hit the enemy with the bullet the event is triggered, however the Game Object Hit shows none instead of the bullet in the inspector and the debug info in playMaker editor, it's simply not recorded. Why the event triggers but the Game Object Hit shows none?

Also my player is a trigger too. But when I walk my player into the enemy the event is not even triggered! I paused and examined that the player and the enemy are indeed collided, even overlapping, but that does't not triggers the event.

The only time the event is triggered and the Game Object Hit is successfully recorded is the time when the enemy move into the ground. Now the object hit will show Static Sprite Batcher which indicates my ground brick.

I have tried to unchecked the "is trigger" on all these hit objects excepts the enemy but it doesn't make a difference. Why is the event only triggers for some object but not others (they all have a collider and can be a trigger or not) and only record object hit for the ground? I really can't figure out. Please Help!
« Last Edit: September 03, 2013, 03:36:38 PM by ryf9059 »

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Trigger enter not working! Help!
« Reply #1 on: September 03, 2013, 04:55:39 PM »
cant give you answer... but im actually going to do the same for my game... (its 2D side-scroller strategy game)
and i was wondering how to remove health based on different units that are shooting the enemies, for example: tank doesnt do the same damage as soldier :) 
i was wondering how to detect which bullet is hitting the enemy...

this post pointed me in the right direction... can you post some pics of FSM's?  it will probably help you get answer too :)


ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Trigger enter not working! Help!
« Reply #2 on: September 03, 2013, 05:59:30 PM »
cant give you answer... but im actually going to do the same for my game... (its 2D side-scroller strategy game)
and i was wondering how to remove health based on different units that are shooting the enemies, for example: tank doesnt do the same damage as soldier :) 
i was wondering how to detect which bullet is hitting the enemy...

this post pointed me in the right direction... can you post some pics of FSM's?  it will probably help you get answer too :)

Sure you can try setup fsm first and see it you get anything.

My player, enemy, ground are all colliders, except for the ground everything else are trigger as well

This is the FSM for enemy, pretty simple. Don't worry about the grayed out action.


The objectHit is a GameObject that stores the hit object, self explanatory.

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Trigger enter not working! Help!
« Reply #3 on: September 04, 2013, 10:18:29 AM »
Bump for attention.


Please help, getting stuck and cannot continue.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Trigger enter not working! Help!
« Reply #4 on: September 04, 2013, 10:36:49 AM »
Get Trigger Info is for getting the Information on a Trigger. The only info is the physics material, which is not what you want.

Trigger Event is the action for storing Trigger event information. When two objects collide it is a Trigger Event, which activates this action. (This action is for Colliders that have Is Trigger checked*)

You'll want to use the Store Collider dropdown to put the projectile into a variable, then do Get Name and store it in a variable, then do a string compare to fire an event that applies the appropriate damage for that named projectile.

* You may be looking for Get Collision Info or Collision Event if not using Triggers.

This part of the system can be tricky to understand, so try not to get too frustrated. =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Trigger enter not working! Help!
« Reply #5 on: September 04, 2013, 10:53:14 AM »
hah yeh you got that right... i was trying to get it to work yesterday for 3 hours+ :) finally gave up at 4AM :)

the only missing puzzle that took most of time away was, "get name" action. thank you alot for that :)

i just didnt know how to store the name of game object to string, so that i can do if statements next to see who damaged him

when im done, i'll post screenshots here...

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Trigger enter not working! Help!
« Reply #6 on: September 04, 2013, 11:17:33 AM »
Get Trigger Info is for getting the Information on a Trigger. The only info is the physics material, which is not what you want.

Trigger Event is the action for storing Trigger event information. When two objects collide it is a Trigger Event, which activates this action. (This action is for Colliders that have Is Trigger checked*)

You'll want to use the Store Collider dropdown to put the projectile into a variable, then do Get Name and store it in a variable, then do a string compare to fire an event that applies the appropriate damage for that named projectile.

* You may be looking for Get Collision Info or Collision Event if not using Triggers.

This part of the system can be tricky to understand, so try not to get too frustrated. =)

Finally help is coming! =D

So yeah this is pretty confused. Do you mean I have to fire a trigger event myself every time something collides?

I thought trigger info can get both game object hit and the physical material (as they are two drop down box shown), but again, this event is not always triggered when collision happens between trigger, or should I say any object enter my trigger, and the object is not always recorded.

More over, is get trigger info supposed to catch all object that last enter the trigger? Because I have the get trigger info after trigger enter event and still nothing is recorded sometimes.
https://hutonggames.fogbugz.com/default.asp?W371

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Trigger enter not working! Help!
« Reply #7 on: September 04, 2013, 11:28:58 AM »
So yeah this is pretty confused. Do you mean I have to fire a trigger event myself every time something collides?

Only if you want something to happen, like get damage from a bullet. You could do this on the enemy instead of the bullet but its better to do it on the bullet, I think, because you can only run one simultaneous state in an FSM to handle damage so the bullet is best to take care of reducing the enemy health variable in this situation. You could make a queuing sort of system to stack up incoming damage, then handle them as fast as the enemy FSM can. I haven't tried this yet.

Quote
I thought trigger info can get both game object hit and the physical material (as they are two drop down box shown), but again, this event is not always triggered when collision happens between trigger, or should I say any object enter my trigger, and the object is not always recorded.

Ah my mistake, I saw the action and thought something totally different. Are you using the Is Trigger box on the collider? It may not be triggering because you have this manager on the enemy, so a bullet hits him, he processes it, then returns to waiting for another collision. If during that time another bullet hits him he doesn't care to process it because he is busy doing other things.

Quote
More over, is get trigger info supposed to catch all object that last enter the trigger? Because I have the get trigger info after trigger enter event and still nothing is recorded sometimes.
https://hutonggames.fogbugz.com/default.asp?W371

This is probably a logic issue with your FSM. It will get the first object and do whatever you tell it to do after that, if it leaves the state then it's no longer looking for collisions.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Trigger enter not working! Help!
« Reply #8 on: September 04, 2013, 11:36:53 AM »
okey so my FSM is fully working now...


trigger event: first it detects trigger, then it stores it as GameObject called collider,
Check ammo type event: gets the name of that collider variable, then it compares it to known ammo types
then depending on type of ammo, it sends event that changes damage variable
then it destroys collider
and removes health


i only have 1 slight problem with it... there is no fail safe feature there...

in Check ammo type state, there is go back action, i want to use that action, in case that no string matches to any String Compare actions

how would i do that?   would it work if i add on last string compare,   "if not equal event, then use go back event"?


oh and i am using this FSM on zombies (enemy)

you suggested something with putting this FSM on bullets?  what is the best option here?
« Last Edit: September 04, 2013, 11:39:28 AM by bizilux »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Trigger enter not working! Help!
« Reply #9 on: September 04, 2013, 11:47:20 AM »
On your last string compare you can use the Not Equal event to fire Go Back.

The state runs events Top-down, so if the last compare fails then it means there was no match. You may get an infinite loop doing this if the collider stays in the collision zone but doesn't match either bullet types.

The reason I suggest looking at putting the fsm on the bullet is because if more than one bullet hit the enemy at the same time then the enemy can only process one and will likely miss the other(s). If the bullet controls this then you can use them grab the collider(enemy) and reduce the health variable remotely meaning all collisions should technically register but it may affect performance by having an FSM on every bullet.

I've been thinking about keeping it on the enemy and using arraymaker to let the bullets add to an array, building a queue of collisions to process. Haven't moved ahead with it though. You could always just set the parent to the enemy, stop the projectile and use Get Next Child, if its null then wait, if not then process the collision and run the damage. I guess thats similar.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

bizilux

  • Full Member
  • ***
  • Posts: 171
Re: Trigger enter not working! Help!
« Reply #10 on: September 04, 2013, 12:06:18 PM »
yep thats what i was thinking of

Quote
You may get an infinite loop doing this if the collider stays in the collision zone but doesn't match either bullet types.
trigger is set to "on trigger enter"  so i think it should be without infinitive loops... i will test that later on i guess¸

Quote
The reason I suggest looking at putting the fsm on the bullet is because if more than one bullet hit the enemy at the same time then the enemy can only process one and will likely miss the other(s).
yes, thats quite valid concern... it takes very little time for FSM to run its loop, but it still takes some time, and if 2 bullets hit at the same time, then only 1 will get registered yes...
i cant have that chance of failure in my game :/


Quote
but it may affect performance by having an FSM on every bullet.
i dont think that should be too much of a problem since bullets get destroyed fairly quickly, they only exist for like 1 second in my game

i would most probably have more enemies than bullets on screen... or it would be fairly even matched... and as far as i've read... hopefully correctly, FSM's take very little performance to do...


EDIT: ok i spawned 20 bullets at exact same coordinates, it registered them all... so i think theres no need for all that extra trouble :)

its basically instant FSM, detects everything. :) nice
« Last Edit: September 04, 2013, 12:15:45 PM by bizilux »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Trigger enter not working! Help!
« Reply #11 on: September 04, 2013, 12:18:21 PM »

EDIT: ok i spawned 20 bullets at exact same coordinates, it registered them all... so i think theres no need for all that extra trouble :)

its basically instant FSM, detects everything. :) nice

good to know! thanks for sharing your findings =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Trigger enter not working! Help!
« Reply #12 on: September 04, 2013, 12:28:16 PM »
Ah my mistake, I saw the action and thought something totally different. Are you using the Is Trigger box on the collider? It may not be triggering because you have this manager on the enemy, so a bullet hits him, he processes it, then returns to waiting for another collision. If during that time another bullet hits him he doesn't care to process it because he is busy doing other things.

Yes I'm using is trigger box on both the bullet and the collider and have a fsm on enemy as I have posted in the screenshot in the above post. There is a trigger enter global event and there is a check collision type state, and within it the action is trigger info, as you can see.
So I do have this manager on the enemy, but when a bullet hits him I do see him possess it since the game object hit in none. This happens even I only fire a single bullet, so there is no other bullet that keeps him busy.
But even let's say there are multiple bullets that hit him after possessing the first bullet he is busy with handling other bullet collision and doesn't care to possess the first bullet, but still when all bullets are hit he should possess the last bullet that hits him right? But again the Game Object is none during the whole time.

Quote
This is probably a logic issue with your FSM. It will get the first object and do whatever you tell it to do after that, if it leaves the state then it's no longer looking for collisions.

My FSM is posted in the screenshot in the above post, it's pretty simple. So the fact is that it doesn't not get my first object, even there is only a single bullet, the state triggers and it's inside the check collision type, but nothing is recorded. Additionally, if my player as a trigger walk into him the state will not even be triggered! It only triggers and possesses the object when it touches the ground sprite, and nothing else.

That's what baffles me.



EDIT: I think I know the reason now, my bullet actually destroy itself after hitting the enemy, I don't know what the exact mechanic is for storing hit object, if it's storing a pointer to the bullet then it will likely get nothing right?
« Last Edit: September 05, 2013, 01:23:19 PM by ryf9059 »

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Trigger enter not working! Help!
« Reply #13 on: September 05, 2013, 12:09:38 PM »
Bump.

Still need getting help

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Trigger enter not working! Help!
« Reply #14 on: September 05, 2013, 08:34:15 PM »
Quote
EDIT: I think I know the reason now, my bullet actually destroy itself after hitting the enemy, I don't know what the exact mechanic is for storing hit object, if it's storing a pointer to the bullet then it will likely get nothing right?

Haven't had a chance to catch up on the whole thread, but that's probably the problem... You could add a delay to the bullet destroying itself to see if that's it...