playMaker

Author Topic: gameObject triggers two triggerevents  (Read 201 times)

BadgerBear

  • Playmaker Newbie
  • *
  • Posts: 3
gameObject triggers two triggerevents
« on: July 17, 2021, 01:11:47 PM »
Good day!
I am very new (noob) to all of this, please excuse my explanation.

I made 2 gameObjects that serves as individual triggers. Both to the same Item(a Key).
Lets call them Trigger A and B and the item will be call key
Trigger A triggers an animation of a chest opening when the key gets close
Trigger B deactivates key and reset positions it where it was in the beginning.

My problem comes when 1 triggers goes off the other one also activates.
I think both A and B sees the keys state as "the trigger happened so I must do the rest" hence both going off.

Any Suggestions??

DABYX

  • Playmaker Newbie
  • *
  • Posts: 8
Re: gameObject triggers two triggerevents
« Reply #1 on: July 20, 2021, 02:59:30 AM »
I'm very new also so sorry if this isn't helpful.
I misread your post initially so had to rethink.

Is there a reason you have 2 trigger gameobjects?

Could you not just have 1 but with either 2 FSM for each action you want to perform or state/string or int switches?

If you need the separate gameobjects then a state compare/switch would also work.
Eg. On open chest object, check state and state switch/compare if on trigger state then disable own fsm? Or similar.

Migsterium

  • Playmaker Newbie
  • *
  • Posts: 6
Re: gameObject triggers two triggerevents
« Reply #2 on: July 22, 2021, 01:12:18 PM »
Hello! You don't need 2 separate triggers for this setup. If I understand correctly, you want the following states & actions to happen in this order:

1. Key and Chest are separate. The chest is closed
2. If the Key gets too close to the Chest it triggers an animation of the Chest opening
3. When the animation is finished, the Key's position is reset.

There are many ways to accomplish this with PlayMaker, I recommend the following setup:

1. Add a box collider component to the Chest and on the inspector click on the checkbox that says Is Trigger.
2. You can change the box collider's size, make sure it is slightly bigger than the Chest's 3D model. This will be range that determines how close the Key must be in order to trigger the Chest's animation.
3. Create a new item tag. To do this select the key's 3D model on the hierarchy window and on the inspector there is a section that says "tag" right under the object's name. Most 3D objects are untagged when you place them on the scene, so click on the menu and select the option "Add tag...", then click on the + symbol to add a tag and name it however you want (I suggest "ChestKey")
4. Change the Key 3D model's tag from "untagged" to your newly created tag
5. Add a new PlayMaker FSM to the Chest.
6. On the State 1 put an action called Trigger Event. This action will detect whether an object with a specific tag has entered or exited the Chest's box collider. In your case you want to trigger an event when the Key has entered the Chest's range so next you have to create a couple of events
7. On the Events tab in the PlayMaker editor create 2 new events named "KeyDetected" and "KeyLost". To do this simply type the name of the event in the text input field and press ENTER for each event. Do not click on the Event Browser or the small button next to the text input field!
8. Return to the State tab on the PlayMaker editor and fill the Trigger Event action info. On the Game Object leave it as "Use Owner", on Trigger use "On Trigger Enter", for Collide Tab select "ChestKey" or the name of the tag you created on step 3, and on Send Event select the "KeyDetected" event. You can leave the Store Collider section empty, you don't need it for this.
9. You'll get an error message in the editor telling you the Event is not used in this state or any global event. Click on that red text to create the KeyDetected Event on State 1.
10. Create another state in that same Playmaker FSM and link State 1 to State 2. To do this click on on the KeyDetected Event on State 1 and drag it to State 2, this will create an arrow from the KeyDetected event leading to State 2
11. On State 2 place another playmaker action called "Play Animation". I'm assuming your chest already has an animation component to play its open animation, if it doesn't this Playmaker action can create this component by clicking on the red text.
12. Write down the name of your animation on the "Anim name" field and on the Finished Event use the "KeyLost" event.
13. Create a third and final state on the Playmaker Editor and link the KeyLost event to the third state, same as in step 10.
14. On the third state add an action called "Set Position", change the Game Object from Owner to "Specify Game Object" and drag your Key item from the scene hierarchy to the Playmaker action slot where it says "None". Finally, write down the coordinates where you want to move your key to move after the Chest's animation has finished. There's another very similar Playmaker action called Set Rotation if you also want to reset the Key's rotation.

Hope this helps you!
« Last Edit: July 22, 2021, 01:20:03 PM by Migsterium »