0 votes

something like

var direction = get_angle_to(get_global_mouse_position())
var target_angle = 0
var turn_speed = deg2rad(1)
if abs(direction) < turn_speed:
    rotation += direction
else:
    if direction > 0: rotation += turn_speed
    if direction < 0: rotation -= turn_speed

but instead of a mouse, a gamepad joystick
so that the sprite looks in the same direction as the controller's joystick is directed

in Engine by (141 points)

1 Answer

0 votes

Hi,
This isn't a total solution to what you want, but it should point you in the right direction (no pun intended ;-) )

how-to-aim-right-game-pad-analog-stick

by (1,865 points)

I tried to do this, but I need the sprite to rotate to the left if the point where you want to turn closer than if you rotate to the right side

var direction = Vector2(Input.get_joy_axis(0, JOY_ANALOG_RX), Input.get_joy_axis(0, JOY_ANALOG_RY)).angle()
var target_angle = 0
var turn_speed = deg2rad(1)
if abs(direction) < turn_speed:
    rotation += direction
else:
    if rotation < direction: rotation += turn_speed
    if rotation > direction: rotation -= turn_speed

if the mouse can be considered an object, and the angle for the player with the mouse is calculated between the mouse and the player himself, then is it possible to create an object and attach it to the player who plays with the gamepad, attach the script that you threw me off and use the script that I specified in the question is only already referring to the position of this object. Only I can't imagine how to attach this object to the player and make it so that it does not rotate along with the rotation of the player. The player is a tank, and the body can be moved separately and the cannon can be moved separately.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.