2020-01-29 17:04:04 +01:00
|
|
|
# Calculates an angular acceleration to match an agent's orientation to its
|
|
|
|
# direction of travel.
|
2020-04-03 02:31:59 +02:00
|
|
|
# @category - Individual behaviors
|
2020-02-11 18:33:25 +01:00
|
|
|
class_name GSAILookWhereYouGo
|
|
|
|
extends GSAIMatchOrientation
|
2019-12-19 21:24:40 +01:00
|
|
|
|
|
|
|
|
2023-01-13 13:09:18 +01:00
|
|
|
func _init(agent: GSAISteeringAgent, use_z : bool = false).(agent, null, use_z) -> void:
|
2019-12-19 21:24:40 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
func _calculate_steering(accel: GSAITargetAcceleration) -> void:
|
2019-12-19 21:24:40 +01:00
|
|
|
if agent.linear_velocity.length_squared() < agent.zero_linear_speed_threshold:
|
|
|
|
accel.set_zero()
|
|
|
|
else:
|
2023-01-13 13:09:18 +01:00
|
|
|
var orientation : float
|
|
|
|
|
|
|
|
if use_z:
|
|
|
|
orientation = GSAIUtils.vector3_to_angle(agent.linear_velocity)
|
|
|
|
else:
|
|
|
|
orientation = GSAIUtils.vector2_to_angle(GSAIUtils.to_vector2(agent.linear_velocity))
|
|
|
|
|
2020-02-06 20:46:21 +01:00
|
|
|
_match_orientation(accel, orientation)
|