More method cleanups.

This commit is contained in:
Relintai 2023-01-13 20:08:32 +01:00
parent 4f5eb0a3a1
commit 07f03b04f8
6 changed files with 11 additions and 9 deletions

View File

@ -18,7 +18,7 @@ func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
_first_minimum_separation = 0
_first_distance = 0
var neighbor_count : int = proximity._find_neighbors(_callback)
var neighbor_count : int = proximity.find_neighbors(_callback)
if neighbor_count == 0 or not _first_neighbor:
acceleration.set_zero()

View File

@ -11,6 +11,7 @@ class_name GSAIBlend
extends GSAISteeringBehavior
var _behaviors : Array = Array()
#note only add a getter
var _accel : GSAITargetAcceleration = GSAITargetAcceleration.new()
# Appends a behavior to the internal array along with its `weight`.

View File

@ -11,7 +11,7 @@ func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
acceleration.set_zero()
_center_of_mass = Vector3.ZERO
var neighbor_count = proximity._find_neighbors(_callback)
var neighbor_count = proximity.find_neighbors(_callback)
if neighbor_count > 0:
_center_of_mass *= 1.0 / neighbor_count
acceleration.linear = ((_center_of_mass - agent.position).normalized() * agent.linear_acceleration_max)

View File

@ -11,14 +11,14 @@ extends GSAIGroupBehavior
# The coefficient to calculate how fast the separation strength decays with distance.
var decay_coefficient : float = 1.0
var _acceleration : GSAITargetAcceleration
var acceleration : GSAITargetAcceleration
func _calculate_steering(acceleration : GSAITargetAcceleration) -> void:
func _calculate_steering(_acceleration : GSAITargetAcceleration) -> void:
acceleration.set_zero()
self._acceleration = acceleration
self.acceleration = _acceleration
# warning-ignore:return_value_discarded
proximity._find_neighbors(_callback)
proximity.find_neighbors(_callback)
# Callback for the proximity to call when finding neighbors. Determines the amount of
@ -34,6 +34,6 @@ func _report_neighbor(neighbor : GSAISteeringAgent) -> bool:
if strength > acceleration_max:
strength = acceleration_max
_acceleration.linear += to_agent * (strength / sqrt(distance_squared))
acceleration.linear += to_agent * (strength / sqrt(distance_squared))
return true

View File

@ -17,10 +17,9 @@ var agent : GSAISteeringAgent
# Sets the `acceleration` with the behavior's desired amount of acceleration.
func calculate_steering(acceleration: GSAITargetAcceleration) -> void:
if is_enabled:
_calculate_steering(acceleration)
call("_calculate_steering", acceleration)
else:
acceleration.set_zero()
func _calculate_steering(acceleration: GSAITargetAcceleration) -> void:
acceleration.set_zero()

View File

@ -9,6 +9,8 @@ var agent : GSAISteeringAgent
# The agents who are part of this group and could be potential neighbors
var agents : Array = Array()
func find_neighbors(_callback: FuncRef) -> int:
return call("_find_neighbors", _callback)
# Returns a number of neighbors based on a `callback` function.
#