Topic was automatically imported from the old Question2Answer platform.
Asked By
Timofey
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
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
Timofey | 2020-10-04 15:24
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.