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.
|
2020-01-29 05:56:10 +01:00
|
|
|
class_name GSTFace
|
|
|
|
extends GSTMatchOrientation
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _init(agent: GSTSteeringAgent, target: GSTAgentLocation).(agent, target) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-02-06 20:46:21 +01:00
|
|
|
func _face(acceleration: GSTTargetAcceleration, target_position: Vector3) -> void:
|
2020-01-16 09:44:44 +01:00
|
|
|
var to_target := target_position - agent.position
|
|
|
|
var distance_squared := to_target.length_squared()
|
2020-01-29 17:04:04 +01:00
|
|
|
|
2019-12-19 20:04:08 +01:00
|
|
|
if distance_squared < agent.zero_linear_speed_threshold:
|
|
|
|
acceleration.set_zero()
|
|
|
|
else:
|
2020-01-29 16:04:47 +01:00
|
|
|
var orientation = GSTUtils.vector3_to_angle(to_target)
|
2020-02-06 20:46:21 +01:00
|
|
|
_match_orientation(acceleration, orientation)
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
2020-02-06 20:46:21 +01:00
|
|
|
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
|
|
|
|
_face(acceleration, target.position)
|