From a9df2d584236abe59b07780984ce10b85fddda82 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 13 Jan 2023 20:47:26 +0100 Subject: [PATCH] More cleanups. --- .../Agents/GSAIKinematicBody2DAgent.gd | 14 +++++++------- .../Agents/GSAIKinematicBody3DAgent.gd | 14 +++++++------- .../Agents/GSAIRigidBody2DAgent.gd | 10 +++++----- .../Agents/GSAIRigidBody3DAgent.gd | 10 +++++----- .../Agents/GSAISpecializedAgent.gd | 4 ++-- .../Behaviors/GSAIPriority.gd | 7 +++---- .../GSAIPath.gd | 4 ++-- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd index 84f2a53..59fa2bb 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody2DAgent.gd @@ -31,7 +31,7 @@ func _body_ready() -> void: # Moves the agent's `body` by target `acceleration`. # @tags - virtual func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: - _applied_steering = true + applied_steering = true if movement_type == MovementType.COLLIDE: _apply_collide_steering(acceleration.linear, delta) @@ -122,10 +122,10 @@ func _set_body(value: KinematicBody2D) -> void: _body_ref = weakref(body) _last_position = value.global_position - _last_orientation = value.rotation + last_orientation = value.rotation position = GSAIUtils.to_vector3(_last_position) - orientation = _last_orientation + orientation = last_orientation if !had_body: if !body.is_inside_tree(): @@ -146,18 +146,18 @@ func _on_SceneTree_physics_frame() -> void: orientation = current_orientation if calculate_velocities: - if _applied_steering: - _applied_steering = false + if applied_steering: + applied_steering = false else: linear_velocity = GSAIUtils.clampedv3(GSAIUtils.to_vector3(current_position - _last_position), linear_speed_max) if apply_linear_drag: linear_velocity = linear_velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage) - angular_velocity = clamp(_last_orientation - current_orientation, -angular_speed_max, angular_speed_max) + angular_velocity = clamp(last_orientation - current_orientation, -angular_speed_max, angular_speed_max) if apply_angular_drag: angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage) _last_position = current_position - _last_orientation = current_orientation + last_orientation = current_orientation diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd index 0b0700e..ec18b40 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIKinematicBody3DAgent.gd @@ -31,7 +31,7 @@ func _body_ready() -> void: # Moves the agent's `body` by target `acceleration`. # @tags - virtual func _apply_steering(acceleration: GSAITargetAcceleration, delta: float) -> void: - _applied_steering = true + applied_steering = true if movement_type == MovementType.COLLIDE: _apply_collide_steering(acceleration.linear, delta) elif movement_type == MovementType.SLIDE: @@ -115,10 +115,10 @@ func _set_body(value: KinematicBody) -> void: _body_ref = weakref(value) _last_position = value.transform.origin - _last_orientation = value.rotation.y + last_orientation = value.rotation.y position = _last_position - orientation = _last_orientation + orientation = last_orientation if !had_body: if !body.is_inside_tree(): @@ -142,18 +142,18 @@ func _on_SceneTree_physics_frame() -> void: orientation = current_orientation if calculate_velocities: - if _applied_steering: - _applied_steering = false + if applied_steering: + applied_steering = false else: linear_velocity = GSAIUtils.clampedv3(current_position - _last_position, linear_speed_max) if apply_linear_drag: linear_velocity = linear_velocity.linear_interpolate(Vector3.ZERO, linear_drag_percentage) - angular_velocity = clamp(_last_orientation - current_orientation,-angular_speed_max,angular_speed_max) + angular_velocity = clamp(last_orientation - current_orientation,-angular_speed_max,angular_speed_max) if apply_angular_drag: angular_velocity = lerp(angular_velocity, 0, angular_drag_percentage) _last_position = current_position - _last_orientation = current_orientation + last_orientation = current_orientation diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd index c4726db..d2d2306 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody2DAgent.gd @@ -23,7 +23,7 @@ func _apply_steering(acceleration : GSAITargetAcceleration, _delta : float) -> v if not _body: return - _applied_steering = true + applied_steering = true _body.apply_central_impulse(GSAIUtils.to_vector2(acceleration.linear)) _body.apply_torque_impulse(acceleration.angular) if calculate_velocities: @@ -41,10 +41,10 @@ func _set_body(value: RigidBody2D) -> void: _body_ref = weakref(value) _last_position = value.global_position - _last_orientation = value.rotation + last_orientation = value.rotation position = GSAIUtils.to_vector3(_last_position) - orientation = _last_orientation + orientation = last_orientation if !had_body: if !body.is_inside_tree(): @@ -68,8 +68,8 @@ func _on_SceneTree_frame() -> void: orientation = current_orientation if calculate_velocities: - if _applied_steering: - _applied_steering = false + if applied_steering: + applied_steering = false else: linear_velocity = GSAIUtils.to_vector3(_body.linear_velocity) angular_velocity = _body.angular_velocity diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd index 456af46..8ed0122 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAIRigidBody3DAgent.gd @@ -22,7 +22,7 @@ func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> voi if !_body: return - _applied_steering = true + applied_steering = true _body.apply_central_impulse(acceleration.linear) _body.apply_torque_impulse(Vector3.UP * acceleration.angular) if calculate_velocities: @@ -40,10 +40,10 @@ func _set_body(value: RigidBody) -> void: _body_ref = weakref(value) _last_position = value.transform.origin - _last_orientation = value.rotation.y + last_orientation = value.rotation.y position = _last_position - orientation = _last_orientation + orientation = last_orientation if !had_body: if !body.is_inside_tree(): @@ -66,8 +66,8 @@ func _on_SceneTree_frame() -> void: orientation = current_orientation if calculate_velocities: - if _applied_steering: - _applied_steering = false + if applied_steering: + applied_steering = false else: linear_velocity = _body.linear_velocity angular_velocity = _body.angular_velocity.y diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAISpecializedAgent.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAISpecializedAgent.gd index 9596c40..7468051 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAISpecializedAgent.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Agents/GSAISpecializedAgent.gd @@ -29,8 +29,8 @@ var linear_drag_percentage : float = 0.0 # Does not apply to `RigidBody` and `RigidBody2D` nodes. var angular_drag_percentage : float = 0.0 -var _last_orientation : float = 0.0 -var _applied_steering : bool = false +var last_orientation : float = 0.0 +var applied_steering : bool = false func apply_steering(_acceleration : GSAITargetAcceleration, _delta : float) -> void: call("_apply_steering", _acceleration, _delta) diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPriority.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPriority.gd index e158b85..f6f82dc 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPriority.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPriority.gd @@ -4,14 +4,13 @@ class_name GSAIPriority extends GSAISteeringBehavior -var _behaviors : Array = Array() - -# The index of the last behavior the container prioritized. -var _last_selected_index : int = 0 # If a behavior's acceleration is lower than this threshold, the container # considers it has an acceleration of zero. var zero_threshold : float = 0.0 +# The index of the last behavior the container prioritized. +var _last_selected_index : int = 0 +var _behaviors : Array = Array() # Appends a steering behavior as a child of this container. func add_behavior(behavior: GSAISteeringBehavior) -> void: diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd index c5f2cfd..8b77d71 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd @@ -58,7 +58,7 @@ func calculate_distance(agent_current_position : Vector3) -> float: for i in range(_segments.size()): var segment: GSAISegment = _segments[i] - var distance_squared : float = calculate_point_segment_distance_squared(segment.begin, segment.end, agent_current_position) + var distance_squared : float = _calculate_point_segment_distance_squared(segment.begin, segment.end, agent_current_position) if distance_squared < smallest_distance_squared: _nearest_point_on_path = _nearest_point_on_segment @@ -105,7 +105,7 @@ func get_end_point() -> Vector3: return _segments.back().end -func calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float: +func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, position: Vector3) -> float: _nearest_point_on_segment = start var start_end : Vector3 = end - start var start_end_length_squared : float = start_end.length_squared()