How to translate the position of a gamepad analog stick to a rotation? (twin stick shooter)

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

I have a 3D sprite model. One of the children of that sprite is a weapon (KinematicBody node). I want to rotate that weapon along the Y axis based on the position of the analog stick. Eg. if the analog stick is pointing to the left I want to point the weapon in the same direction (360 degree coverage). Think games like Enter the Gungeon.
For reference, I’m using an XBox One controller
Input.get_joy_axis(0, JOY_AXIS_2) is the X axis
Input.get_joy_axis(0, JOY_AXIS_3) is the Y axis

:bust_in_silhouette: Reply From: ATom 1
if y>=0:
    if x==0:
elif y<0:
    if x==0:
degrees=r*360/(PI*2) (0~360)

The above is pseudo code

position== (1.0,0.0) => degrees==0

does godot have deadzone support built in? if so, how do you customize that? (I checked the input docs, I don’t see any reference to configuring deadzone)

if godot doesn’t handle deadzone, make sure you do!

Jason Swearingen | 2020-01-07 13:20

I found this in the documentation, there is a deadzong related function
InputMap — Godot Engine (latest) documentation in English

It seems that you don’t know much about trigonometric functions. If this is the case, no matter how I help you,it will be difficult for you. You should all learn trigonometric functions.

ATom 1 | 2020-01-07 14:59

thanks for the link on deadzones! I swear I searched for that but didn’t see it :frowning:

Jason Swearingen | 2020-01-07 18:08