Godot Engine

Godot Engine

pikadon92 Apr 10, 2020 @ 12:09am
[SOLVED] Analog axis strength issue
As I test my analog controls, sometimes the coordinates return to the original position even though I'm keeping the analog in one direction, though this happens when I tilt it to another direction.

Given the following var that I set as the following actions:
export (String) var input_left = "ui_left" export (String) var input_right = "ui_right" export (String) var input_up = "ui_up" export (String) var input_down = "ui_down" var dir = Vector2()

I have written a function where after taking event as an input, it gives Vector2 as an output:
func directional_event(event)->Vector2: if event is InputEventJoypadMotion: if event.get_action_strength(input_left): dir.x = -event.get_action_strength(input_left) elif event.get_action_strength(input_right): dir.x = event.get_action_strength(input_right) elif event.get_action_strength(input_up): dir.y = -event.get_action_strength(input_up) elif event.get_action_strength(input_down): dir.y = event.get_action_strength(input_down) else: dir = Vector2() return dir pass

I have observed that as I, say, turn right, then go upwards a little, the vector resets as (0, 0). Does anyone how I could fix this? My initial solution is to remove the "dir = Vector2()" branch, but the function won't return Vector2() once I let go of the analog.
Last edited by pikadon92; Apr 10, 2020 @ 4:10am
< >
Showing 1-2 of 2 comments
pikadon92 Apr 10, 2020 @ 2:39am 
Okay, so I didn't account for deadzones while implementing analog controls. but the problem still exists, only that it's limited to rotation (eg. right to top-right to up). Maybe I need to get the axis number...
pikadon92 Apr 10, 2020 @ 4:08am 
Found the solution myself. I can check whether the event is on a specific axis by calling event.is_action(action) where action is the name of either direction of an axis. This is what I did that works:
func directional_event(event)->Vector2: if event is InputEventJoypadMotion: if event.is_action(input_left): if event.get_action_strength(input_left): dir.x = -event.get_action_strength(input_left) else: dir.x = event.get_action_strength(input_right) elif event.is_action(input_up): if event.get_action_strength(input_up): dir.y = -event.get_action_strength(input_up) else: dir.y = event.get_action_strength(input_down) return dir pass
Last edited by pikadon92; Apr 10, 2020 @ 4:10am
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Apr 10, 2020 @ 12:09am
Posts: 2