diff --git a/docs/quickstart.md b/docs/quickstart.md index c95036e..cee7834 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -123,7 +123,7 @@ func _ready() -> void: # Behaviors that are not enabled produce 0 acceleration. # Adding our fleeing behaviors to a blend. The order does not matter. - flee_blend.enabled = false + flee_blend.is_enabled = false flee_blend.add(look, 1) flee_blend.add(flee, 1) @@ -144,8 +144,8 @@ func _physics_process(delta: float) -> void: update_agent() if current_health <= flee_health_threshold: - pursue_blend.enabled = false - flee_blend.enabled = true + pursue_blend.is_enabled = false + flee_blend.is_enabled = true # Calculate the desired acceleration. priority.calculate_steering(acceleration) diff --git a/project/demos/GroupBehaviors/Member.tscn b/project/demos/GroupBehaviors/Member.tscn index a569388..fbd24df 100644 --- a/project/demos/GroupBehaviors/Member.tscn +++ b/project/demos/GroupBehaviors/Member.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://demos/GroupBehaviors/Member.gd" type="Script" id=1] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] - [sub_resource type="CircleShape2D" id=1] radius = 16.0 diff --git a/project/demos/Quickstart/Agent.gd b/project/demos/Quickstart/Agent.gd index 26e2704..1731c32 100644 --- a/project/demos/Quickstart/Agent.gd +++ b/project/demos/Quickstart/Agent.gd @@ -90,7 +90,7 @@ func _ready() -> void: # Behaviors that are not enabled produce 0 acceleration. # Adding our fleeing behaviors to a blend. The order does not matter. - flee_blend.enabled = false + flee_blend.is_enabled = false flee_blend.add(look, 1) flee_blend.add(flee, 1) @@ -111,8 +111,8 @@ func _physics_process(delta: float) -> void: update_agent() if current_health <= flee_health_threshold: - pursue_blend.enabled = false - flee_blend.enabled = true + pursue_blend.is_enabled = false + flee_blend.is_enabled = true # Calculate the desired acceleration. priority.calculate_steering(acceleration) diff --git a/project/demos/SeekFlee/Seeker.tscn b/project/demos/SeekFlee/Seeker.tscn index cf2e52d..3ffce34 100644 --- a/project/demos/SeekFlee/Seeker.tscn +++ b/project/demos/SeekFlee/Seeker.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://demos/SeekFlee/Seeker.gd" type="Script" id=1] [ext_resource path="res://assets/sprites/small_circle.png" type="Texture" id=2] - [sub_resource type="CircleShape2D" id=1] radius = 16.0 diff --git a/project/src/Behaviors/GSTAvoidCollisions.gd b/project/src/Behaviors/GSTAvoidCollisions.gd index 7725d47..93fa352 100644 --- a/project/src/Behaviors/GSTAvoidCollisions.gd +++ b/project/src/Behaviors/GSTAvoidCollisions.gd @@ -22,7 +22,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele first_minimum_separation = 0 first_distance = 0 - var neighbor_count := proximity.find_neighbors(_callback) + var neighbor_count := proximity._find_neighbors(_callback) if neighbor_count == 0 or not first_neighbor: acceleration.set_zero() @@ -42,7 +42,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele # Callback for the proximity to call when finding neighbors. Keeps track of every `neighbor` # that was found but only keeps the one the owning agent will most likely collide with. -func report_neighbor(neighbor: GSTSteeringAgent) -> bool: +func _report_neighbor(neighbor: GSTSteeringAgent) -> bool: var relative_position := neighbor.position - agent.position var relative_velocity := neighbor.linear_velocity - agent.linear_velocity var relative_speed_squared := relative_velocity.length_squared() diff --git a/project/src/Behaviors/GSTCohesion.gd b/project/src/Behaviors/GSTCohesion.gd index b25fd8c..346045d 100644 --- a/project/src/Behaviors/GSTCohesion.gd +++ b/project/src/Behaviors/GSTCohesion.gd @@ -14,7 +14,7 @@ func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: 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 @@ -23,6 +23,6 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele # Callback for the proximity to call when finding neighbors. Adds `neighbor`'s position # to the center of mass of the group. -func report_neighbor(neighbor: GSTSteeringAgent) -> bool: +func _report_neighbor(neighbor: GSTSteeringAgent) -> bool: center_of_mass += neighbor.position return true diff --git a/project/src/Behaviors/GSTFollowPath.gd b/project/src/Behaviors/GSTFollowPath.gd index 78b5a08..9d634c9 100644 --- a/project/src/Behaviors/GSTFollowPath.gd +++ b/project/src/Behaviors/GSTFollowPath.gd @@ -9,7 +9,7 @@ var path: GSTPath var path_offset := 0.0 # Whether to use `GSTArrive` behavior on an open path. -var arrive_enabled := true +var is_arrive_enabled := true # The amount of time in the future to predict the owning agent's position along # the path. Setting it to 0.0 will force non-predictive path following. var prediction_time := 0.0 @@ -35,7 +35,7 @@ func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAccele var target_position := path.calculate_target_position(target_distance) - if arrive_enabled and path.open: + if is_arrive_enabled and path.is_open: if path_offset >= 0: if target_distance > path.length - deceleration_radius: return _arrive(acceleration, target_position) diff --git a/project/src/Behaviors/GSTSeparation.gd b/project/src/Behaviors/GSTSeparation.gd index cb47c53..175fd73 100644 --- a/project/src/Behaviors/GSTSeparation.gd +++ b/project/src/Behaviors/GSTSeparation.gd @@ -21,13 +21,13 @@ func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent, proximity) func _calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: acceleration.set_zero() self.acceleration = acceleration - proximity.find_neighbors(_callback) + proximity._find_neighbors(_callback) return acceleration # Callback for the proximity to call when finding neighbors. Determines the amount of # acceleration that `neighbor` imposes based on its distance from the owner agent. -func report_neighbor(neighbor: GSTSteeringAgent) -> bool: +func _report_neighbor(neighbor: GSTSteeringAgent) -> bool: var to_agent := agent.position - neighbor.position var distance_squared := to_agent.length_squared() diff --git a/project/src/GSTGroupBehavior.gd b/project/src/GSTGroupBehavior.gd index 4336e71..06b1b7e 100644 --- a/project/src/GSTGroupBehavior.gd +++ b/project/src/GSTGroupBehavior.gd @@ -1,12 +1,12 @@ # Base type for group-based steering behaviors. -extends GSTSteeringBehavior class_name GSTGroupBehavior +extends GSTSteeringBehavior # Container to find neighbors of the agent and calculate group behavior. var proximity: GSTProximity -var _callback := funcref(self, "report_neighbor") +var _callback := funcref(self, "_report_neighbor") func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void: @@ -15,5 +15,5 @@ func _init(agent: GSTSteeringAgent, proximity: GSTProximity).(agent) -> void: # Internal callback for the behavior to define whether or not a member is # relevant -func report_neighbor(neighbor: GSTSteeringAgent) -> bool: +func _report_neighbor(neighbor: GSTSteeringAgent) -> bool: return false diff --git a/project/src/GSTPath.gd b/project/src/GSTPath.gd index 3c1ffd9..62b0ac8 100644 --- a/project/src/GSTPath.gd +++ b/project/src/GSTPath.gd @@ -1,10 +1,11 @@ # Represents a path made up of Vector3 waypoints, split into segments path # follow behaviors can use. -extends Reference class_name GSTPath +class_name GSTPath +extends Reference # If `false`, the path loops. -var open: bool +var is_open: bool # Total length of the path. var length: float @@ -14,8 +15,8 @@ var _nearest_point_on_segment: Vector3 var _nearest_point_on_path: Vector3 -func _init(waypoints: Array, open := false) -> void: - self.open = open +func _init(waypoints: Array, is_open := false) -> void: + self.is_open = is_open create_path(waypoints) _nearest_point_on_segment = waypoints[0] _nearest_point_on_path = waypoints[0] @@ -36,7 +37,7 @@ func create_path(waypoints: Array) -> void: previous = current if i < waypoints.size(): current = waypoints[i] - elif open: + elif is_open: break else: current = waypoints[0] @@ -74,7 +75,7 @@ func calculate_distance(agent_current_position: Vector3) -> float: # Calculates a target position from the path's starting point based on the `target_distance`. func calculate_target_position(target_distance: float) -> Vector3: - if open: + if is_open: target_distance = clamp(target_distance, 0, length) else: if target_distance < 0: diff --git a/project/src/GSTSteeringAgent.gd b/project/src/GSTSteeringAgent.gd index fa58033..7302f5f 100644 --- a/project/src/GSTSteeringAgent.gd +++ b/project/src/GSTSteeringAgent.gd @@ -25,4 +25,4 @@ var angular_velocity := 0.0 var bounding_radius := 0.0 # Used internally by group behaviors and proximities to mark the agent as already # considered. -var tagged := false +var is_tagged := false diff --git a/project/src/GSTSteeringBehavior.gd b/project/src/GSTSteeringBehavior.gd index d0bd881..c89a92f 100644 --- a/project/src/GSTSteeringBehavior.gd +++ b/project/src/GSTSteeringBehavior.gd @@ -9,7 +9,7 @@ class_name GSTSteeringBehavior # If `false`, all calculations return zero amounts of acceleration. -var enabled := true +var is_enabled := true # The AI agent on which the steering behavior bases its calculations. var agent: GSTSteeringAgent @@ -21,7 +21,7 @@ func _init(agent: GSTSteeringAgent) -> void: # Returns the `acceleration` modified with the behavior's desired amount of # acceleration. func calculate_steering(acceleration: GSTTargetAcceleration) -> GSTTargetAcceleration: - if enabled: + if is_enabled: return _calculate_steering(acceleration) else: acceleration.set_zero() diff --git a/project/src/Proximities/GSTInfiniteProximity.gd b/project/src/Proximities/GSTInfiniteProximity.gd index dbe358c..0435561 100644 --- a/project/src/Proximities/GSTInfiniteProximity.gd +++ b/project/src/Proximities/GSTInfiniteProximity.gd @@ -10,9 +10,9 @@ func _init(agent: GSTSteeringAgent, agents: Array).(agent, agents) -> void: # Returns a number of neighbors based on a `callback` function. # -# `find_neighbors` calls `callback` for each agent in the `agents` array and +# `_find_neighbors` calls `callback` for each agent in the `agents` array and # adds one to the count if its `callback` returns true. -func find_neighbors(callback: FuncRef) -> int: +func _find_neighbors(callback: FuncRef) -> int: var neighbor_count := 0 var agent_count := agents.size() for i in range(agent_count): diff --git a/project/src/Proximities/GSTProximity.gd b/project/src/Proximities/GSTProximity.gd index 0439cad..f421bc6 100644 --- a/project/src/Proximities/GSTProximity.gd +++ b/project/src/Proximities/GSTProximity.gd @@ -16,7 +16,7 @@ func _init(agent: GSTSteeringAgent, agents: Array) -> void: # Returns a number of neighbors based on a `callback` function. # -# `find_neighbors` calls `callback` for each agent in the `agents` array and +# `_find_neighbors` calls `callback` for each agent in the `agents` array and # adds one to the count if its `callback` returns true. -func find_neighbors(callback: FuncRef) -> int: +func _find_neighbors(callback: FuncRef) -> int: return 0 diff --git a/project/src/Proximities/GSTRadiusProximity.gd b/project/src/Proximities/GSTRadiusProximity.gd index 1c0c58b..4b56d50 100644 --- a/project/src/Proximities/GSTRadiusProximity.gd +++ b/project/src/Proximities/GSTRadiusProximity.gd @@ -18,9 +18,9 @@ func _init(agent: GSTSteeringAgent, agents: Array, radius: float).(agent, agents # Returns a number of neighbors based on a `callback` function. # -# `find_neighbors` calls `callback` for each agent in the `agents` array that lie within +# `_find_neighbors` calls `callback` for each agent in the `agents` array that lie within # the radius around the owning agent and adds one to the count if its `callback` returns true. -func find_neighbors(callback: FuncRef) -> int: +func _find_neighbors(callback: FuncRef) -> int: var agent_count := agents.size() var neighbor_count := 0 @@ -40,16 +40,16 @@ func find_neighbors(callback: FuncRef) -> int: if distance_squared < range_to * range_to: if callback.call_func(current_agent): - current_agent.tagged = true + current_agent.is_tagged = true neighbor_count += 1 continue - current_agent.tagged = false + current_agent.is_tagged = false else: for i in range(agent_count): var current_agent = agents[i] as GSTSteeringAgent - if current_agent != agent and current_agent.tagged: + if current_agent != agent and current_agent.is_tagged: if callback.call_func(current_agent): neighbor_count += 1