diff --git a/project/demos/Arrive/Arriver.gd b/project/demos/Arrive/Arriver.gd index dc7e196..0d3b81d 100644 --- a/project/demos/Arrive/Arriver.gd +++ b/project/demos/Arrive/Arriver.gd @@ -12,7 +12,7 @@ var _drag := 0.1 func _physics_process(delta: float) -> void: arrive.calculate_steering(_accel) - agent.apply_steering(_accel, delta) + agent._apply_steering(_accel, delta) func setup( diff --git a/project/demos/AvoidCollisions/Avoider.gd b/project/demos/AvoidCollisions/Avoider.gd index 894ae7e..dfb8281 100644 --- a/project/demos/AvoidCollisions/Avoider.gd +++ b/project/demos/AvoidCollisions/Avoider.gd @@ -31,7 +31,7 @@ func _physics_process(delta: float) -> void: target.position.y = agent.position.y + _direction.y*_radius priority.calculate_steering(_accel) - agent.apply_steering(_accel, delta) + agent._apply_steering(_accel, delta) func setup( diff --git a/project/demos/Face/Turret.gd b/project/demos/Face/Turret.gd index 30ca245..8326837 100644 --- a/project/demos/Face/Turret.gd +++ b/project/demos/Face/Turret.gd @@ -20,7 +20,7 @@ func _ready() -> void: func _physics_process(delta: float) -> void: face.calculate_steering(_accel) - agent.apply_steering(_accel, delta) + agent._apply_steering(_accel, delta) func _draw() -> void: diff --git a/project/demos/FollowPath/PathFollower.gd b/project/demos/FollowPath/PathFollower.gd index 67dd256..d9b54cb 100644 --- a/project/demos/FollowPath/PathFollower.gd +++ b/project/demos/FollowPath/PathFollower.gd @@ -36,7 +36,7 @@ func setup( func _physics_process(delta: float) -> void: if _valid: follow.calculate_steering(_accel) - agent.apply_steering(_accel, delta) + agent._apply_steering(_accel, delta) func _on_Drawer_path_established(points: Array) -> void: diff --git a/project/demos/GroupBehaviors/Member.gd b/project/demos/GroupBehaviors/Member.gd index 4fe6168..183a681 100644 --- a/project/demos/GroupBehaviors/Member.gd +++ b/project/demos/GroupBehaviors/Member.gd @@ -46,7 +46,7 @@ func _draw() -> void: func _physics_process(delta: float) -> void: if blend: blend.calculate_steering(acceleration) - agent.apply_steering(acceleration, delta) + agent._apply_steering(acceleration, delta) func set_neighbors(neighbor: Array) -> void: diff --git a/project/demos/SeekFlee/Seeker.gd b/project/demos/SeekFlee/Seeker.gd index 896a420..a18d111 100644 --- a/project/demos/SeekFlee/Seeker.gd +++ b/project/demos/SeekFlee/Seeker.gd @@ -27,4 +27,4 @@ func _physics_process(delta: float) -> void: else: flee.calculate_steering(accel) - agent.apply_steering(accel, delta) + agent._apply_steering(accel, delta) diff --git a/project/project.godot b/project/project.godot index 11a6b05..888d2b6 100644 --- a/project/project.godot +++ b/project/project.godot @@ -153,6 +153,11 @@ _global_script_classes=[ { "class": "GSTUtils", "language": "GDScript", "path": "res://src/GSTUtils.gd" +}, { +"base": "EditorScript", +"class": "ReferenceCollector", +"language": "GDScript", +"path": "res://ReferenceCollector.gd" } ] _global_script_class_icons={ "GSTAgentLocation": "", @@ -183,7 +188,8 @@ _global_script_class_icons={ "GSTSteeringAgent": "", "GSTSteeringBehavior": "", "GSTTargetAcceleration": "", -"GSTUtils": "" +"GSTUtils": "", +"ReferenceCollector": "" } [application] diff --git a/project/src/Agents/GSTKinematicBody2DAgent.gd b/project/src/Agents/GSTKinematicBody2DAgent.gd index 4854939..4e01ba9 100644 --- a/project/src/Agents/GSTKinematicBody2DAgent.gd +++ b/project/src/Agents/GSTKinematicBody2DAgent.gd @@ -4,6 +4,9 @@ extends GSTSpecializedAgent class_name GSTKinematicBody2DAgent +# SLIDE uses `move_and_slide` +# COLLIDE uses `move_and_collide` +# POSITION changes the `global_position` directly enum MovementType { SLIDE, COLLIDE, POSITION } @@ -11,17 +14,14 @@ enum MovementType { SLIDE, COLLIDE, POSITION } var body: KinematicBody2D setget _set_body # The type of movement the body executes -# -# SLIDE uses use move_and_slide -# COLLIDE uses move_and_collide -# POSITION changes the global_position directly var movement_type: int var _last_position: Vector2 func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> void: - yield(body, "ready") + if not body.is_inside_tree(): + yield(body, "ready") self.body = body self.movement_type = movement_type @@ -31,7 +31,7 @@ func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> vo # Moves the agent's `body` by target `acceleration`. # tags: virtual -func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: _applied_steering = true match movement_type: MovementType.COLLIDE: diff --git a/project/src/Agents/GSTKinematicBodyAgent.gd b/project/src/Agents/GSTKinematicBodyAgent.gd index 3744047..da84d23 100644 --- a/project/src/Agents/GSTKinematicBodyAgent.gd +++ b/project/src/Agents/GSTKinematicBodyAgent.gd @@ -3,7 +3,9 @@ extends GSTSpecializedAgent class_name GSTKinematicBodyAgent - +# SLIDE uses `move_and_slide` +# COLLIDE uses `move_and_collide` +# POSITION changes the global_position directly enum MovementType { SLIDE, COLLIDE, POSITION } @@ -11,17 +13,14 @@ enum MovementType { SLIDE, COLLIDE, POSITION } var body: KinematicBody setget _set_body # The type of movement the body executes -# -# SLIDE uses use move_and_slide -# COLLIDE uses move_and_collide -# POSITION changes the global_position directly var movement_type: int var _last_position: Vector3 func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void: - yield(body, "ready") + if not body.is_inside_tree(): + yield(body, "ready") self.body = body self.movement_type = movement_type @@ -31,7 +30,7 @@ func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void # Moves the agent's `body` by target `acceleration`. # tags: virtual -func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: _applied_steering = true match movement_type: MovementType.COLLIDE: diff --git a/project/src/Agents/GSTRigidBody2DAgent.gd b/project/src/Agents/GSTRigidBody2DAgent.gd index bb52652..43e2a6b 100644 --- a/project/src/Agents/GSTRigidBody2DAgent.gd +++ b/project/src/Agents/GSTRigidBody2DAgent.gd @@ -11,16 +11,15 @@ var _last_position: Vector2 func _init(body: RigidBody2D) -> void: + if not body.is_inside_tree(): + yield(body, "ready") + self.body = body - if body.is_inside_tree(): - body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") - else: - body.connect("ready", self, "_on_body_ready") # Moves the agent's `body` by target `acceleration`. # tags: virtual -func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: _applied_steering = true body.apply_central_impulse(GSTUtils.to_vector2(acceleration.linear)) body.apply_torque_impulse(acceleration.angular) diff --git a/project/src/Agents/GSTRigidBodyAgent.gd b/project/src/Agents/GSTRigidBodyAgent.gd index 499e6c4..c3d189c 100644 --- a/project/src/Agents/GSTRigidBodyAgent.gd +++ b/project/src/Agents/GSTRigidBodyAgent.gd @@ -11,16 +11,17 @@ var _last_position: Vector3 func _init(body: RigidBody) -> void: + if not body.is_inside_tree(): + yield(body, "ready") + self.body = body - if body.is_inside_tree(): - body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") - else: - body.connect("ready", self, "_on_body_ready") + body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") + # Moves the agent's `body` by target `acceleration`. # tags: virtual -func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: _applied_steering = true body.apply_central_impulse(acceleration.linear) body.apply_torque_impulse(Vector3.UP * acceleration.angular) diff --git a/project/src/Agents/GSTSpecializedAgent.gd b/project/src/Agents/GSTSpecializedAgent.gd index 55b0bdf..2f97b7d 100644 --- a/project/src/Agents/GSTSpecializedAgent.gd +++ b/project/src/Agents/GSTSpecializedAgent.gd @@ -9,12 +9,12 @@ class_name GSTSpecializedAgent # frame. When `false`, the user must keep those values updated. var calculate_velocities := true -# If `true` and velocities and `calculate_velocities` is true, interpolates +# If `true` and `calculate_velocities` is true, interpolates # the current linear velocity towards 0 by the `linear_drag_percentage` value. # Does not apply to `RigidBody` and `RigidBody2D` nodes. var apply_linear_drag := true -# If `true` and velocities and `calculate_velocities` is true, interpolates +# If `true` and `calculate_velocities` is true, interpolates # the current angular velocity towards 0 by the `angular_drag_percentage` value. # Does not apply to `RigidBody` and `RigidBody2D` nodes. var apply_angular_drag := true @@ -36,5 +36,5 @@ var _applied_steering := false # Moves the agent's body by target `acceleration`. # tags: virtual -func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: +func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void: pass