playMaker

Author Topic: FSM and Prefab Clones [SOLVED]  (Read 4902 times)

Ticked_Off_Pixel

  • Playmaker Newbie
  • *
  • Posts: 31
    • http://happystar-adventures.tumblr.com/
FSM and Prefab Clones [SOLVED]
« on: January 11, 2013, 08:50:13 AM »
Hello everyone,

I'm having a problem when setting up a group of objects that were all created from the same prefab but will perform differently in the game world, depending on their location.

For example: In my game, if the prefab(clone) is in the position X, they will Enable a FSM to change colour. All others prefab(clone) objects will remain the same, with their FSM Disabled.

But what happens is, when any of the prefabs reach the Trigger point, the FSM of all the clones become Enabled.  >:(

What can I do to separate these Clones behaviours?

Thanks!
« Last Edit: January 11, 2013, 02:38:16 PM by Ticked_Off_Pixel »

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: FSM and Prefab Clones
« Reply #1 on: January 11, 2013, 09:00:51 AM »
It sounds like you are using a global variable to determine the position of them - thats why if one prefab goes to position X, they will all recognise it becasue it's a global var

To prevent this, simple make the determining variable a local variable instead of a global one - that way each prefab will determine its position on its own instead of globally

If this doesn't help - give us some more information on how you determine position - is it a simple box collider, or do you use a bool? if it's a bool, then it's because its global
Remember, you don't fail unless you give up trying to succeed!

Ticked_Off_Pixel

  • Playmaker Newbie
  • *
  • Posts: 31
    • http://happystar-adventures.tumblr.com/
Re: FSM and Prefab Clones
« Reply #2 on: January 11, 2013, 09:36:25 AM »
The Prefab has a FSM where on State 1 the following actions are present:

Disable FSM: With 'Use Owner' to disable another FSM in the sabe object.

Get Position:  I check the location with Get Position (with Use Owner), storing the value in a Local Variable.

Float Compare: Then, on the same state, I use Float Compare, to see with the position matches, sending an Event to transition to State 2, where I will Enable the FSM that was disable in this same state.

Apparently, all the clones are getting the same value for the Local Variable, even if their Get Position should give the variable a different value.

Any ideas?

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: FSM and Prefab Clones
« Reply #3 on: January 11, 2013, 09:46:01 AM »
when sending an event to transition to state 2 (after determining that the gameobject is in the correct place)

is that "send event" sending to itself (use owner)? because if you specified it's name then it will send it to every gameobject with that name in the scene - may I suggest using a box collider to trigger when a gameobject walks into it?

It may be easier to just create an empty gameobject, give it a collider and check "is trigger" and make sure the trigger is placed where you want it to be - then on the gameobject that walks into it, add a listener for trigger event, and when it detects a collision with the trigger, it will go into state 2.. thats state 2 being the current state1 of the FSM you want to activate - just have it active all the time but add a new state as state 1 that listens for that collision
Remember, you don't fail unless you give up trying to succeed!

Ticked_Off_Pixel

  • Playmaker Newbie
  • *
  • Posts: 31
    • http://happystar-adventures.tumblr.com/
Re: FSM and Prefab Clones
« Reply #4 on: January 11, 2013, 01:13:35 PM »
Thanks for the sugestion, Koz.

I think it would work, but I found out what was wrong.

I forgot to add a Get Position in the Enabled state, so, all the Clones got stuck in the enabled state, even when they left the area where they would be disabled.

I hope I don't kicked out from asking stupid questions in this forum!  ;D

Thanks a lot!