android: fix deadzone calculation
This commit is contained in:
parent
13b29c3f49
commit
e5bdb7011b
1 changed files with 12 additions and 4 deletions
|
@ -76,10 +76,18 @@ class InputHandler {
|
||||||
|
|
||||||
// Adjust range of joystick
|
// Adjust range of joystick
|
||||||
val deadzone = 0.15f
|
val deadzone = 0.15f
|
||||||
|
var x = xAxis
|
||||||
|
var y = yAxis
|
||||||
|
|
||||||
|
if (r > deadzone) {
|
||||||
val deadzoneFactor = 1.0f / r * (r - deadzone) / (1.0f - deadzone)
|
val deadzoneFactor = 1.0f / r * (r - deadzone) / (1.0f - deadzone)
|
||||||
var x = xAxis * deadzoneFactor
|
x *= deadzoneFactor
|
||||||
var y = yAxis * deadzoneFactor
|
y *= deadzoneFactor
|
||||||
r *= deadzoneFactor
|
r *= deadzoneFactor
|
||||||
|
} else {
|
||||||
|
x = 0.0f
|
||||||
|
y = 0.0f
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize joystick
|
// Normalize joystick
|
||||||
if (r > 1.0f) {
|
if (r > 1.0f) {
|
||||||
|
|
Loading…
Reference in a new issue