+1 vote

Hi,
I have some issues with gamepad controls. I want to aim around player node using sticks X and Y axis. Instead of smooth movement in 360 degrees range, it aims every 45 degrees. Aiming in directions between those angles is possible, but rather hard. May it be fault of the gamepad? Is there any possibility to make aiming with stick more smooth and precise?
My code for now:

func control(delta): 
if abs(Input.get_joy_axis(0, JOY_AXIS_3)) > deadZone or 
    abs(Input.get_joy_axis(0,JOY_AXIS_2)) > deadZone:
              cannon_stick_dir = Vector2(Input.get_joy_axis(0, JOY_AXIS_3) * -1, 
                      Input.get_joy_axis(0, JOY_AXIS_2))
var cannon_position = $Cannon.get_rotation()  * 0.85 #* 1.10714872  
if cannon_position != cannon_stick_dir.angle():
    cannon_dir_vector = Vector2(cos($Cannon.get_rotation()), 
            sin($Cannon.get_rotation()))
    if cannon_position != cannon_stick_dir.angle():
        if cannon_dir_vector.angle_to(cannon_stick_dir) >= 0:
            rot_dir -= 1
            $Cannon.rotation = (rot_speed * rot_dir * delta) 
        elif cannon_dir_vector.angle_to(cannon_stick_dir) < 0:
            rot_dir += 1
            $Cannon.rotation = (rot_speed * rot_dir * delta) 
        else:
            rot_speed = 0
asked Jan 7, 2019 in Engine by Kwakwarakwa (13 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.