Mapping sprite rotation to L stick

Godot Version

v4.2.2.stable.official [15073afe3]


Hi, I’m trying to map sprite rotation of a character to the gamepad left stick. Can someone walk me through the code for that? I’ve found a bunch of tutorials on how to make the sprite rotate to look at the mouse, but I want to rotate with the gamepad stick. I have all the input maps configured, and have figured out how to rotate the sprite in the four main directions, but I can’t get smooth 360 degree rotation.

Here’s the four direction rotation code I have if it helps.


func _process(delta):
if Input.is_action_pressed(“up”):
rotation_degrees = -45
if Input.is_action_pressed(“right”):
rotation_degrees = 45
if Input.is_action_pressed(“down”):
rotation_degrees = 135
if Input.is_action_pressed(“left”):
rotation_degrees = -135

I now have 8 directions with and commands for each diagonal.

Get the input vector, then you can compute the angle of that vector

var input_direction := Input.get_vector("left", "right", "up", "down")
rotation = input_direction.angle()

Wow thanks so much. Why couldn’t I find this on the internet…

How to I get the rotation to stay at the last value instead of going back to 0 degrees when I let go of the stick?

use an if statement

var input_direction := Input.get_vector("left", "right", "up", "down")
if input_direction: # not zero
    rotation = input_direction.angle()
1 Like


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.