I have an enemy that turns towards the player I used the angletopoint () function to calculate the angle of the enemy relative to the player's position and saved the value in a variable, each frame the enemy looks towards the player but when the value of the player's angle is negative (jumps from 3.0 to -3.0) the enemy makes a full turn instead of following the player continuously Here is the code in the RigidBody2D(the enemy):
onready var player = get_parent().get_node("player")
func _process(delta):
var angle_pos = player.position.angle_to_point(get_global_position())
set_angular_velocity(0)
# this just means set the angular velocity towards the player if
# it's angle to point value is less than the rotation of the enemy
if stepify(rotation, 0.05) > stepify(angle_pos, 0.05):
set_angular_velocity(-1)
if stepify(rotation, 0.05) < stepify(angle_pos, 0.05):
set_angular_velocity(1)
here I leave a video that shows the problem: https://youtu.be/bzrN_YvcVhA