2020-01-29 17:04:04 +01:00
|
|
|
# Calculates an acceleration to take an agent to a target agent's position
|
|
|
|
# directly.
|
2020-04-03 02:31:59 +02:00
|
|
|
# @category - Individual behaviors
|
2020-02-11 18:33:25 +01:00
|
|
|
class_name GSAISeek
|
|
|
|
extends GSAISteeringBehavior
|
2019-12-19 20:04:08 +01:00
|
|
|
|
2020-01-29 17:04:04 +01:00
|
|
|
# The target that the behavior aims to move the agent to.
|
2020-02-11 18:33:25 +01:00
|
|
|
var target: GSAIAgentLocation
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
2020-02-11 20:36:06 +01:00
|
|
|
func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation).(agent) -> void:
|
|
|
|
self.target = _target
|
2019-12-19 20:04:08 +01:00
|
|
|
|
|
|
|
|
2020-02-11 18:33:25 +01:00
|
|
|
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
|
2019-12-19 20:04:08 +01:00
|
|
|
acceleration.linear = (
|
2020-02-14 17:35:18 +01:00
|
|
|
(target.position - agent.position).normalized()
|
|
|
|
* agent.linear_acceleration_max
|
|
|
|
)
|
2019-12-19 20:04:08 +01:00
|
|
|
acceleration.angular = 0
|