Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: derkoi on September 19, 2012, 07:27:33 AM
-
I'm trying to create a dead zone from the accelerometer input. I've clamped the float to -1 and 1, I'd like to have an adjustable deadzone at 0, but I'm not sure how to tackle it.
Any suggestions?? Thanks
-
just made this, its not tested but should work
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Clamps between high and low and a deadzone center.")]
public class FloatclampAndDeadZone : FsmStateAction
{
public FsmFloat accelerometerInput;
public FsmFloat minClamp;
public FsmFloat maxClamp;
public FsmFloat minDeadZone;
public FsmFloat maxDeadZone;
public FsmFloat clampOutput;
public bool everyFrame;
public override void Reset()
{
accelerometerInput = 0f;
minClamp = 0f;
maxClamp = 0f;
minDeadZone = 0f;
maxDeadZone = 0f;
clampOutput = 0f;
everyFrame = false;
}
public override void OnEnter()
{
DoCompare();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoCompare();
}
void DoCompare()
{
if (accelerometerInput.Value > minDeadZone.Value &&
accelerometerInput.Value < maxDeadZone.Value)
{
clampOutput.Value = 0;
}
if (accelerometerInput.Value > maxClamp.Value)
{
clampOutput.Value = maxClamp.Value;
}
if (accelerometerInput.Value < minClamp.Value)
{
clampOutput.Value = minClamp.Value;
}
}
}
}
if there is no issue please let me know and can add it to the custom action forum
-
Thanks, it works but doesn't seem to have the desired effect. Might be me though. :)
-
cool, did you want it to ease in and out of the deadzone? it currently leaves the value as it is, if its within the dead zone it just sets it to 0, I can offset the value by the deadzone, so that as soon as you come out of the deadzone it starts counting up giving a smoother transition between deadzone and not
-
Yeah that sounds better suited, thanks. :)
-
Here try this, again untested but should work
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Clamps between high and low and a deadzone center, no jump in or out of deadzone.")]
public class FloatclampAndDeadZone : FsmStateAction
{
public FsmFloat accelerometerInput;
public FsmFloat minClamp;
public FsmFloat maxClamp;
public FsmFloat minDeadZone;
public FsmFloat maxDeadZone;
public FsmFloat clampOutput;
public bool everyFrame;
public override void Reset()
{
accelerometerInput = 0f;
minClamp = 0f;
maxClamp = 0f;
minDeadZone = 0f;
maxDeadZone = 0f;
clampOutput = 0f;
everyFrame = false;
}
public override void OnEnter()
{
DoCompare();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoCompare();
}
void DoCompare()
{
if (accelerometerInput.Value > minDeadZone.Value &&
accelerometerInput.Value < maxDeadZone.Value)
{
clampOutput.Value = 0;
}
if (accelerometerInput.Value > maxClamp.Value)
{
clampOutput.Value = maxClamp.Value;
}
if (accelerometerInput.Value < minClamp.Value)
{
clampOutput.Value = minClamp.Value;
}
if (accelerometerInput.Value > maxDeadZone.Value &&
accelerometerInput.Value < maxClamp.Value)
{
clampOutput.Value = accelerometerInput.Value - maxDeadZone.Value;
}
if (accelerometerInput.Value < minDeadZone.Value &&
accelerometerInput.Value > minClamp.Value)
{
clampOutput.Value = accelerometerInput.Value + minDeadZone.Value;
}
}
}
}
if there is a problem its down to my math, in which case I just need to turn the equation around XP
-
Thanks, the 2nd one works great! ;D