playMaker

Author Topic: Comparing Input.Touches Get Magnitude values in FloatCompare  (Read 1580 times)

felixwcf

  • Playmaker Newbie
  • *
  • Posts: 2
Comparing Input.Touches Get Magnitude values in FloatCompare
« on: April 11, 2017, 04:03:38 AM »
Hi,
I'm using Input.Touches asset with Playmaker.
I'm getting swipe magnitude by using Input Touches Get Magnitude and if the magnitude is below certain value, it will run Pass, else Not Pass.

In first state I get the magnitude and store into global variable swipeMagnitudeGvar.
And in my next state, I use the global variable value to compare with a certain number.

In my FloatCompare,
if(swipeMagnitudeGvar == 20) return Not Pass.
else if(swipeMagnitudeGvar < 20) return Pass.
else if(swipeMagnitudeGvar >20) return Not Pass.
Tolerance = 0.


The problem:
Eveytime I swipe and get the magnitude, FloatCompare is taking the previous value to compare.
e.g
i. Before first-time swipe, initial swipeMagnitudeGvar is 0. So I will get pass no matter what for the first time swipe gesture.
ii. Second and subsequently, it will still get the previous value to compare.

Below is my FSM:
1. Get Magnitude when detecting swipe gesture.

As you can above the value is 121 but it return Pass.

2. This is the state that contains FloatCompare:


Does that means when the FSM is active, the whole FSM mechanism will proceed by "existing" value instead of updated value? How can I pass updated / changed value from state A to state B?

Please help. Thank you.



« Last Edit: April 11, 2017, 05:01:25 AM by felixwcf »

elusiven

  • Full Member
  • ***
  • Posts: 233
  • Debt we all must pay...
Re: Comparing Input.Touches Get Magnitude values in FloatCompare
« Reply #1 on: April 11, 2017, 06:14:32 AM »
Why is that a global variable? They are static, so they stay in the memory. Can you not reset the variable after you've done or in the initial state before checking ? 

felixwcf

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Comparing Input.Touches Get Magnitude values in FloatCompare
« Reply #2 on: April 12, 2017, 09:42:33 AM »
Hi I've solved this.

According to the documentation:



Magnitude : The magnitude of the last event. Applies to Pinch and Rotate gestures

I've written custom script to get the real-time magnitude in Update(), but still I able to get last-state magnitude when doing float compare.

However as you mentioned about global variable, now I have better understanding on global variable and normal variable after studying further. Thank you.

So stupid to waste so many times on little thing. However problem solved by using Input Touch Get Swipe Info and getting the direction of x and y and determine the "swipe amount" of the player.
« Last Edit: April 12, 2017, 11:40:37 AM by felixwcf »