What I am trying to do is to make the ai turn at a set speed to avoid the ship just being able to make an impossibly fast turn towards the player.
I have already managed to make it so that it follow the player like this, and it even works when following a path made from manually placed position2d nodes. But when I try to make it follow a path generated by Navigation2d it just turns to the right and completely ignores the player. Does anyone know why this might be happening? Here is my code:
func _process(delta):
path = get_parent().get_node("Navigation2D").get_simple_path(self.global_position, Player.global_position, false)
$Line2D.points = path
#rotates the object at a limited speed towards the target
rotation = lerp_angle(rotation, global_position.angle_to_point(path[0]), turning_speed)
#calculates the rotation to be used by the movement
var true_rotation_rad = deg2rad(rotation_degrees+180)
#movement
move_and_slide(Vector2(cos(true_rotation_rad), sin(true_rotation_rad)) * speed)
if self.global_position.distance_to(path[0]) <= max_distance:
path.remove(0)