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-04-03 02:31:59 +02:00
|
|
|
# @category - Individual behaviors
|
2020-02-11 18:33:25 +01:00
|
|
|
class_name GSAIFace
|
|
|
|
extends GSAIMatchOrientation
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
2020-02-14 17:35:18 +01:00
|
|
|
func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation, use_z := false).(
|
|
|
|
agent, target, use_z
|
|
|
|
) -> void:
|
2019-12-19 20:04:08 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
func _face(acceleration: GSAITargetAcceleration, 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-02-14 17:35:18 +01:00
|
|
|
var orientation = (
|
|
|
|
GSAIUtils.vector3_to_angle(to_target)
|
2020-02-13 09:33:03 +01:00
|
|
|
if use_z
|
|
|
|
else GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(to_target))
|
|
|
|
)
|
2020-02-06 20:46:21 +01:00
|
|
|
_match_orientation(acceleration, orientation)
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
2020-02-06 20:46:21 +01:00
|
|
|
_face(acceleration, target.position)
|