0 votes

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.getjoyaxis(0, JOYAXIS2) is the X axis
Input.getjoyaxis(0, JOYAXIS3) is the Y axis

asked Jan 7 in Engine by DanteeChaos (12 points)

1 Answer

+1 vote
if y>=0:
    if x==0:
        r=PI/2
    else:
        r=atan(y/x)
elif y<0:
    if x==0:
        r=PI/2+PI
    else:
        r=atan(y/x)+PI
degrees=r*360/(PI*2) (0~360)

The above is pseudo code

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

answered Jan 7 by ATom 1 (209 points)

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!

I found this in the documentation, there is a deadzong related function
https://docs.godotengine.org/en/latest/classes/class_inputmap.html#class-inputmap-method-action-set-deadzone

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.

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

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.