rj-action-library/Runtime/Sensors/Sensors.cs

38 lines
844 B
C#
Raw Normal View History

2024-07-25 05:40:31 +00:00
using Godot;
namespace Rokojori
{
public class Sensors
{
public static bool IsDown( Sensor sensor, int device = 0 )
{
return sensor == null ? false : sensor.IsDown( device );
}
2025-01-08 18:46:17 +00:00
public static bool IsActive( Sensor sensor )
2024-07-25 05:40:31 +00:00
{
2025-01-08 18:46:17 +00:00
return sensor == null ? false : sensor.isActive;
2024-07-25 05:40:31 +00:00
}
public static float GetValue( Sensor sensor, float scale = 1, float deadZone = 0.3f )
2024-07-25 05:40:31 +00:00
{
if ( sensor == null )
{
return 0;
}
var rawValue = sensor.value;
var clamped = MathX.NormalizeClamped( rawValue, deadZone, 1 );
return clamped * scale;
2024-07-25 05:40:31 +00:00
}
public static float PolarAxis( Sensor negative, Sensor positive, float scale = 1, float deadZone = 0.3f )
2024-07-25 05:40:31 +00:00
{
return GetValue( negative, -scale, deadZone ) + GetValue( positive, scale, deadZone );
2024-07-25 05:40:31 +00:00
}
}
}