I have a playercontroller 2d in top-down view game, where the players ship follows the cursor.
I have already done that my ship rotates to cursor with a small latency
code below shows how it was done
var rotation_speed = PI * 1.5 # PI = 180 degrees
func _look_at_mouse(delta):
var v = get_global_mouse_position() - global_position
var angle = v.angle()
var r = global_rotation
var angle_delta = rotation_speed * delta
angle = lerp_angle(r, angle + 1.57, 1.0)
angle = clamp(angle, r - angle_delta, r + angle_delta)
global_rotation = angle
But now I need my ship not only rotate with latency, but also to move not exactly to cursor global position, but to it's position with the same interpolation / latency as the rotation of the ship. I have no idea how to do it, tried many things. Code below represents my move function:
func _move_to_mouse(delta):
if position.distance_to(get_global_mouse_position()) > stop_distance:
var direction = get_global_mouse_position() - position
var normalized_direction = direction.normalized()
var direction_distance = direction.length()
move_and_slide(normalized_direction * max(move_speed, direction_distance))
P.S. I copied this question from same one, because there was no proper answer. Or I just don't understand it. Sorry, if that's my bad.