extends Sprite2D var targetPos = Vector2(0,0); var follow_speed = 1; # input function let's us check different events initiated by the user func _input(event): # is_action_pressed function returns true, if a certain button is pressed, # which is determined by input mapping. In this instance, we listen for left # mouse button pressed by user. if event.is_action_pressed("ui_mouse_left"): targetPos = get_global_mouse_position(); print("hej"); # process function runs pr. frame, which is updating different processes at delta # time. Delta is a variable time interval. func _process(delta): # lerp function makes interpolation between 2 vectors, and determines a route # of points between current position of sprite and the target position. position = position.lerp(targetPos, delta * follow_speed); var smooth_rot = abs(get_angle_to(targetPos) - get_angle_to(position)); # Make a smooth rotation by only rotating by a fraction pr. frame. rotation = rotation + smooth_rot/50;