How can I make my character look at the direction of the stick or mouse respectively?

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

I’m making a 2D Top Down shooter game. Inspired by Enter the Gungeon.
In this game, you can use the mouse or the right joystick, and your player will look at it.

I already know how to make this work with a mouse, as I can get the direction based on the player and the cursor position. It also applies an offset to the camera if it is far enough from the player, to move it a little further to where the character is looking at. However, I don’t know how this would work with a joystick.

I thought of making the cursor able to be controlled by the joystick, but the Input.warp_mouse(Vector2.ZERO) method does not seem to work. I think it also removes my custom cursor image.

I also don’t know if it is a good idea to make a custom cursor with a TextureRect, and move with also with the joystick, as I’ve seen it can have a delay.

If I could make an Input action for the mouse and get a vector based on its position, it would work easily, but the InputMap system seems to only work with buttons.

What could I do?

:bust_in_silhouette: Reply From: Lamb

Sorry I’m not familiar with the game you’re referencing but

var rightStickInput = Input.get_vector("left", "right", "up", "down")

will get you the right stick’s input, if you’ve set it up in
Project > Project Settings > Input Map.

If you can’t get Input.warp_mouse(Vector2.ZERO) working,
I’d give hiding the actual mouse and using a sprite instead a shot.
(Sorry I can’t tell you if it’s the best idea though)

To easily move it around the player, you could do

var mousePosition = transform.origin + ( rightStickInput * 5 )

Sorry if this doesn’t answer everything. But I figured nobody’s responded and this’d give you a start