godot-steering-ai-framework/project/src/GSTSteeringBehavior.gd
Francois Belair 57f3c4a24a Make calculate_acceleration return void
This makes the code more in line with GDQuest gdscript guidelines about
 not both transforming state and returning a value.
2020-02-06 14:46:21 -05:00

31 lines
913 B
GDScript

# Base class for all steering behaviors.
#
# Steering behaviors calculate the linear and the angular acceleration to be
# to the agent that owns them.
#
# The `calculate_steering` function is the entry point for all behaviors.
# Individual steering behaviors encapsulate the steering logic.
class_name GSTSteeringBehavior
# If `false`, all calculations return zero amounts of acceleration.
var is_enabled := true
# The AI agent on which the steering behavior bases its calculations.
var agent: GSTSteeringAgent
func _init(agent: GSTSteeringAgent) -> void:
self.agent = agent
# Sets the `acceleration` with the behavior's desired amount of acceleration.
func calculate_steering(acceleration: GSTTargetAcceleration) -> void:
if is_enabled:
_calculate_steering(acceleration)
else:
acceleration.set_zero()
func _calculate_steering(acceleration: GSTTargetAcceleration) -> void:
acceleration.set_zero()