This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Joypad inputs appear to only give you the direction, not a precise angle

enter image description here

I want the user to be able to aim precisely (setting their 2D angle to the joypad's angle), but with the current input mapping I can only let them aim in 45 degree increments. Is there any way to allow 360 degree turning with joypad input mapping?

in Engine by (700 points)

A partial solution to be used in _physics_process. Unfortunately it 'snaps' the given aim_dir angles.

func _aim(delta):
    #KEYBOARD AIMING
    var up = Input.is_action_pressed("aim_up")
    var down = Input.is_action_pressed("aim_down")
    var left = Input.is_action_pressed("aim_left")
    var right = Input.is_action_pressed("aim_right")
    if up or down or left or right: #do not change aim if none of those inputs were pressed
        var aim_speed = 4

        var aim_dir = 0
        if up and right:
            aim_dir = 315
        elif up and left:
            aim_dir = 225
        elif down and right:
            aim_dir = 45
        elif down and left:
            aim_dir = 135
        elif down:
            aim_dir = 90
        elif up:
            aim_dir = 270
        elif left:
            aim_dir = 180
        elif right:
            aim_dir = 0
        aim_dir = deg2rad(aim_dir)
        var diff = aim_dir - _body.global_rotation
        if abs(diff) > PI:#rotate shortest direction
            diff += - sign(diff) * 2 * PI
        if abs(diff) < PI/50:#stop rotating when close
            diff = 0
        _body.global_rotation += sign(diff) * delta * aim_speed

1 Answer

+1 vote
Best answer

AFAIK, Godot 3.0.2 does not support it.
But there is a WIP PR for it.

https://github.com/godotengine/godot/pull/16902

I guess it will be available on 3.1

by (9,800 points)
selected by
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.