godot-steering-ai-framework/project/src/Behaviors/GSTFace.gd

24 lines
793 B
GDScript3
Raw Normal View History

2020-01-29 17:04:04 +01:00
# Calculates angular acceleration to rotate a target to face its target's
# position. The behavior attemps to arrive with zero remaining angular velocity.
class_name GSTFace
extends GSTMatchOrientation
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
pass
func _face(acceleration: GSTTargetAcceleration, target_position: Vector3) -> void:
var to_target := target_position - agent.position
var distance_squared := to_target.length_squared()
2020-01-29 17:04:04 +01:00
if distance_squared < agent.zero_linear_speed_threshold:
acceleration.set_zero()
else:
var orientation = GSTUtils.vector3_to_angle(to_target)
_match_orientation(acceleration, orientation)
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
_face(acceleration, target.position)