Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: felixwcf on April 11, 2017, 04:03:38 AM

Title: Comparing Input.Touches Get Magnitude values in FloatCompare
Post by: felixwcf 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.
(http://i934.photobucket.com/albums/ad188/chanfui/Screen%20Shot%202017-04-11%20at%202.52.46%20PM%201.png)
As you can above the value is 121 but it return Pass.

2. This is the state that contains FloatCompare:
(http://i934.photobucket.com/albums/ad188/chanfui/Screen%20Shot%202017-04-11%20at%202.53.10%20PM.png)

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.



Title: Re: Comparing Input.Touches Get Magnitude values in FloatCompare
Post by: elusiven 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 ? 
Title: Re: Comparing Input.Touches Get Magnitude values in FloatCompare
Post by: felixwcf on April 12, 2017, 09:42:33 AM
Hi I've solved this.

According to the documentation:

(http://i934.photobucket.com/albums/ad188/chanfui/Screen%20Shot%202017-04-12%20at%209.36.35%20PM.png)

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.