Smoothing rotation when following navigation path.

mcal9909mcal9909 Posts: 1Member
edited December 2017 in 2D

I have an ememy that uses navmesh for path finding. I want the emey to face the direction of the next path position.
everything seem to go wrong when the rotation loops round it results in the enemy spinning quickly in the opposite direction until hes facing the correct way.

var smooth_angle var direction = global_position.angle_to_point(path[0]) var distance = position.distance_to(path[0]) if distance > 100: position = position.linear_interpolate(path[0], (speed * delta) / distance) smooth_angle = lerp(rotation, direction, delta * 6.0) print(smooth_angle) rotation = smooth_angle

when printing the angle the ranges seem to go from -3 to +3 the spinning occurs when i rotate past +3 to -3 and vice versa.
very new to this any help pointing me in the right direction would be appreciated.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file