playMaker

Author Topic: Checking 2 different floats on the same FSM for the same event.[SOLVED]  (Read 2419 times)

terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
EDIT: I found a custom Vector3 compare class so I think I have solved my problem, but my question stands if anyone has time to suggest a solution. It might come up some other day.

Hey, I am new to Unity, Playmaker and programming in general so I realize its probably a very basic question, but I have been trying different things for some time now and no luck.

I have a vector3 for the player's movement. I would like to check if he is moving or not. For this I converted the X and Z into floats (the Y is always zero in my case). It would be great to have a Vector3 compare action but I couldn't find it.

Then I have both the X and Z floats on a Float Compare action (each on his own action), the second float as zero, and I send the event "moving" on both greater than and less than on both.

That causes and infinite loop. If I remove the Z float compare it works fine with just the X, but then if the player is moving only in the Z axis I can't tell.

What would be the best way to solve this? I can't add them I think since they can zero each other out (the Z can be at -25 while the X at 25).

Basically what I need is "if (x>0 and x<0 and z<0 and z>0) {movement}".


Here is what I have, if my words were confusing: https://dl.dropbox.com/u/226993/Screen%20Shot%202013-02-07%20at%208.00.49%20PM.jpg
« Last Edit: February 09, 2013, 02:57:25 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Checking 2 different floats on the same FSM for the same event.
« Reply #1 on: February 08, 2013, 01:36:57 AM »
Hi,

Whyt you need is create a kind ot "toggle" system, where you only send the "move event" and "idle event" when you first detect the change in movement, Just like triggers and collisions, you have a trigger Enter and trigger Exit. Here you need the same.

 so, when you start, you only check if the user moves, if you detect a move you fire a global event for others to act, AND you move to a different state where you check if the user stops moving, in which case you fire that other global event AND come back to the start state.

Now, you may say: but I want to to things in that fsm. It is possible, but you are then confronted with a very common issue that ONLY ONE STATE CAN BE ACTIVE AT A TIME. So simply have that fsmdoing only just that fire global events, and then on the same GameObject perhaps, another fsm that listen to them global events and do stuff with it.

 Does that make sense?

bye,

 Jean


terri

  • Sr. Member
  • ****
  • Posts: 386
    • terrivellmann.tumblr.com
Re: Checking 2 different floats on the same FSM for the same event.
« Reply #2 on: February 08, 2013, 03:34:25 PM »
Yeah, thanks, that makes sense, instead of running them both on the same state I make separate FSM with global events or variables.

The Vector3 compare has been very useful though!