Precise input mapping for JoyPad axis

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jarlowrey

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?

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

func _aim(delta):
	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

jarlowrey | 2018-04-17 23:21

:bust_in_silhouette: Reply From: volzhs

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

I guess it will be available on 3.1

Also - Thanks!

jarlowrey | 2018-04-18 15:10