MarcoFazioRandom / Virtual-Joystick-Godot

A simple virtual joystick for touchscreens, for both 2D and 3D games, with useful options.
MIT License
731 stars 80 forks source link

Increase measurement error for Joystick's corner values #43

Closed redisotschek closed 1 year ago

redisotschek commented 1 year ago

If user wants to go straight sideways or up/down the joystick still works only in diagonal, because this check

if output.x < -0:
    Input.action_press(action_left, -output.x)
elif Input.is_action_pressed(action_left):
    Input.action_release(action_left)

returns true even for the smallest values and it's impossible to hit straight on 0

How about increasing value in check to 0.1 / -0.1?

This works perfectly

func _update_input_actions():
    if output.x < -0.1:
        Input.action_press(action_left, -output.x)
    elif Input.is_action_pressed(action_left):
        Input.action_release(action_left)
    if output.x > 0.1:
        Input.action_press(action_right, output.x)
    elif Input.is_action_pressed(action_right):
        Input.action_release(action_right)
    if output.y < -0.1:
        Input.action_press(action_up, -output.y)
    elif Input.is_action_pressed(action_up):
        Input.action_release(action_up)
    if output.y > 0.1:
        Input.action_press(action_down, output.y)
    elif Input.is_action_pressed(action_down):
        Input.action_release(action_down)
MarcoFazioRandom commented 1 year ago

Hello redisotschek!

If I understand correctly, this behavior is not related to this project, as a real joystick would present the same problem (you can't move the joystick in a perfect single direction).

The issue should be solved afterwards, after you take the value from the input action.

MarcoFazioRandom commented 1 year ago

I'm reopening this issue, after another user opened #45 for the same problem, because I will commit a fix soon.

In short, I will use the value from InputMap.action_get_deadzone() instead of 0.

MarcoFazioRandom commented 1 year ago

Fixed with #46