diff --git a/godot/Demos/Arrive/Arriver.gd b/godot/Demos/Arrive/Arriver.gd index 8646b6b..fae8af2 100644 --- a/godot/Demos/Arrive/Arriver.gd +++ b/godot/Demos/Arrive/Arriver.gd @@ -1,13 +1,17 @@ extends KinematicBody2D -var agent := GSAIKinematicBody2DAgent.new(self) +var agent := GSAIKinematicBody2DAgent.new() var target := GSAIAgentLocation.new() -var arrive := GSAIArrive.new(agent, target) +var arrive := GSAIArrive.new() var _accel := GSAITargetAcceleration.new() var _velocity := Vector2() var _drag := 0.1 +func _init() -> void: + agent.body = self + arrive.agent = agent + arrive.target = target func _physics_process(delta: float) -> void: arrive.calculate_steering(_accel) diff --git a/godot/Demos/Arrive3d/Seeker.gd b/godot/Demos/Arrive3d/Seeker.gd index ad4be91..f7a8455 100644 --- a/godot/Demos/Arrive3d/Seeker.gd +++ b/godot/Demos/Arrive3d/Seeker.gd @@ -2,13 +2,30 @@ extends KinematicBody var target_node: Spatial -onready var agent := GSAIKinematicBody3DAgent.new(self) -onready var target := GSAIAgentLocation.new() -onready var accel := GSAITargetAcceleration.new() -onready var blend := GSAIBlend.new(agent) -onready var face := GSAIFace.new(agent, target, true) -onready var arrive := GSAIArrive.new(agent, target) +var agent : GSAIKinematicBody3DAgent = null +var target : GSAIAgentLocation = null +var accel : GSAITargetAcceleration = null +var blend : GSAIBlend = null +var face : GSAIFace = null +var arrive : GSAIArrive = null +func _init() -> void: + agent = GSAIKinematicBody3DAgent.new() + agent.body = self + + target = GSAIAgentLocation.new() + accel = GSAITargetAcceleration.new() + blend = GSAIBlend.new() + blend.agent = agent + + face = GSAIFace.new() + face.agent = agent + face.target = target + face.use_z = true + + arrive = GSAIArrive.new() + arrive.agent = agent + arrive.target = target func _physics_process(delta: float) -> void: target.position = target_node.transform.origin diff --git a/godot/Demos/AvoidCollisions/Avoider.gd b/godot/Demos/AvoidCollisions/Avoider.gd index 7fcfb17..03143a7 100644 --- a/godot/Demos/AvoidCollisions/Avoider.gd +++ b/godot/Demos/AvoidCollisions/Avoider.gd @@ -12,13 +12,34 @@ var _drag := 0.1 var _color := Color(0.4, 1.0, 0.89, 0.3) onready var collision := $CollisionShape2D -onready var agent := GSAIKinematicBody2DAgent.new(self) -onready var proximity := GSAIRadiusProximity.new(agent, [], 140) -onready var avoid := GSAIAvoidCollisions.new(agent, proximity) -onready var target := GSAIAgentLocation.new() -onready var seek := GSAISeek.new(agent, target) -onready var priority := GSAIPriority.new(agent, 0.0001) +var agent :GSAIKinematicBody2DAgent= null +var proximity :GSAIRadiusProximity= null +var avoid :GSAIAvoidCollisions= null +var target :GSAIAgentLocation= null +var seek :GSAISeek= null +var priority :GSAIPriority= null +func _ready() -> void: + agent = GSAIKinematicBody2DAgent.new() + agent.body = self + + proximity = GSAIRadiusProximity.new() + proximity.agent = agent + proximity.radius = 140 + + avoid = GSAIAvoidCollisions.new() + avoid.agent = agent + avoid.proximity = proximity + + target = GSAIAgentLocation.new() + + seek = GSAISeek.new() + seek.agent = agent + seek.target = target + + priority = GSAIPriority.new() + priority.agent = agent + priority.zero_threshold = 0.0001 func _draw() -> void: if draw_proximity: diff --git a/godot/Demos/Face/Turret.gd b/godot/Demos/Face/Turret.gd index 1657316..586c80a 100644 --- a/godot/Demos/Face/Turret.gd +++ b/godot/Demos/Face/Turret.gd @@ -1,7 +1,7 @@ extends KinematicBody2D var face: GSAIFace -var agent := GSAIKinematicBody2DAgent.new(self) +var agent := GSAIKinematicBody2DAgent.new() var _accel := GSAITargetAcceleration.new() var _angular_drag := 0.1 @@ -12,6 +12,8 @@ onready var collision_shape := $CollisionShape2D func _ready() -> void: + agent.body = self + var radius = collision_shape.shape.radius _cannon = Rect2(Vector2(-5, 0), Vector2(10, -radius * 2)) _color = collision_shape.outer_color @@ -33,7 +35,9 @@ func setup( angular_accel_max: float, angular_speed_max: float ) -> void: - face = GSAIFace.new(agent, player_agent) + face = GSAIFace.new() + face.agent = agent + face.target = player_agent face.alignment_tolerance = align_tolerance face.deceleration_radius = deceleration_radius diff --git a/godot/Demos/FollowPath/PathFollower.gd b/godot/Demos/FollowPath/PathFollower.gd index 4429248..911f5a3 100644 --- a/godot/Demos/FollowPath/PathFollower.gd +++ b/godot/Demos/FollowPath/PathFollower.gd @@ -5,16 +5,24 @@ var _accel := GSAITargetAcceleration.new() var _valid := false var _drag := 0.1 -onready var agent := GSAIKinematicBody2DAgent.new(self) -onready var path := GSAIPath.new( - [ - Vector3(global_position.x, global_position.y, 0), - Vector3(global_position.x, global_position.y, 0) - ], - true -) -onready var follow := GSAIFollowPath.new(agent, path, 0, 0) +var agent := GSAIKinematicBody2DAgent.new() +var path := GSAIPath.new() +var follow := GSAIFollowPath.new() +func _ready() -> void: + agent.body = self + + path.initialize( + [ + Vector3(global_position.x, global_position.y, 0), + Vector3(global_position.x, global_position.y, 0) + ], + true + ) + + follow.agent = agent + follow.path = path + follow.agent = agent func setup( path_offset: float, diff --git a/godot/Demos/GroupBehaviors/Member.gd b/godot/Demos/GroupBehaviors/Member.gd index e068884..52767ae 100644 --- a/godot/Demos/GroupBehaviors/Member.gd +++ b/godot/Demos/GroupBehaviors/Member.gd @@ -3,9 +3,9 @@ extends KinematicBody2D var separation: GSAISeparation var cohesion: GSAICohesion var proximity: GSAIRadiusProximity -var agent := GSAIKinematicBody2DAgent.new(self) -var blend := GSAIBlend.new(agent) -var acceleration := GSAITargetAcceleration.new() +var agent :GSAIKinematicBody2DAgent = null +var blend : GSAIBlend = null +var acceleration : GSAITargetAcceleration = null var draw_proximity := false var _color := Color.red @@ -13,6 +13,14 @@ var _velocity := Vector2() onready var collision_shape := $CollisionShape2D +func _init() -> void: + agent = GSAIKinematicBody2DAgent.new() + agent.body = self + + blend = GSAIBlend.new() + blend.agent = agent + + acceleration = GSAITargetAcceleration.new() func setup( linear_speed_max: float, @@ -29,10 +37,19 @@ func setup( agent.linear_speed_max = linear_speed_max agent.linear_drag_percentage = 0.1 - proximity = GSAIRadiusProximity.new(agent, [], proximity_radius) - separation = GSAISeparation.new(agent, proximity) + proximity = GSAIRadiusProximity.new() + proximity.agent = agent + proximity.radius = proximity_radius + + separation = GSAISeparation.new() + separation.agent = agent + separation.proximity = proximity separation.decay_coefficient = separation_decay_coefficient - cohesion = GSAICohesion.new(agent, proximity) + + cohesion = GSAICohesion.new() + cohesion.agent = agent + cohesion.proximity = proximity + blend.add(separation, separation_strength) blend.add(cohesion, cohesion_strength) diff --git a/godot/Demos/PursueSeek/Pursuer.gd b/godot/Demos/PursueSeek/Pursuer.gd index 04ebdf6..020d8f1 100644 --- a/godot/Demos/PursueSeek/Pursuer.gd +++ b/godot/Demos/PursueSeek/Pursuer.gd @@ -9,12 +9,18 @@ var _linear_drag_coefficient := 0.025 var _angular_drag := 0.1 var _direction_face := GSAIAgentLocation.new() -onready var agent := GSAIKinematicBody2DAgent.new(self) -onready var accel := GSAITargetAcceleration.new() -onready var player_agent: GSAISteeringAgent = owner.find_node("Player", true, false).agent +var agent : GSAIKinematicBody2DAgent= null +var accel : GSAITargetAcceleration = null +var player_agent : GSAISteeringAgent = null func _ready() -> void: + agent = GSAIKinematicBody2DAgent.new() + agent.body = self + + accel = GSAITargetAcceleration.new() + player_agent = owner.find_node("Player", true, false).agent + agent.calculate_velocities = false set_physics_process(false) @@ -45,15 +51,24 @@ func _physics_process(delta: float) -> void: func setup(predict_time: float, linear_speed_max: float, linear_accel_max: float) -> void: var behavior: GSAISteeringBehavior if use_seek: - behavior = GSAISeek.new(agent, player_agent) + behavior = GSAISeek.new() + behavior.agent = agent + behavior.target = player_agent else: - behavior = GSAIPursue.new(agent, player_agent, predict_time) + behavior = GSAIPursue.new() + behavior.agent = agent + behavior.target = player_agent + behavior.predict_time_max = predict_time - var orient_behavior := GSAIFace.new(agent, _direction_face) + var orient_behavior : GSAIFace = GSAIFace.new() + orient_behavior.agent = agent + orient_behavior.target = _direction_face + orient_behavior.alignment_tolerance = deg2rad(5) orient_behavior.deceleration_radius = deg2rad(30) - _blend = GSAIBlend.new(agent) + _blend = GSAIBlend.new() + _blend.agent = agent _blend.add(behavior, 1) _blend.add(orient_behavior, 1) diff --git a/godot/Demos/Quickstart/Agent.gd b/godot/Demos/Quickstart/Agent.gd index 5c90316..79cab27 100644 --- a/godot/Demos/Quickstart/Agent.gd +++ b/godot/Demos/Quickstart/Agent.gd @@ -18,35 +18,54 @@ var linear_drag := 0.1 var angular_drag := 0.1 # Holds the linear and angular components calculated by our steering behaviors. -var acceleration := GSAITargetAcceleration.new() +var acceleration : GSAITargetAcceleration = null onready var current_health := health_max # GSAISteeringAgent holds our agent's position, orientation, maximum speed and acceleration. -onready var agent := GSAISteeringAgent.new() +var agent : GSAISteeringAgent = null -onready var player: Node = get_tree().get_nodes_in_group("Player")[0] +var player: Node = null # This assumes that our player class will keep its own agent updated. -onready var player_agent: GSAISteeringAgent = player.agent +var player_agent : GSAISteeringAgent = null # Proximities represent an area with which an agent can identify where neighbors in its relevant # group are. In our case, the group will feature the player, which will be used to avoid a # collision with them. We use a radius proximity so the player is only relevant inside 100 pixels. -onready var proximity := GSAIRadiusProximity.new(agent, [player_agent], 100) +var proximity : GSAIRadiusProximity = null # GSAIBlend combines behaviors together, calculating all of their acceleration together and adding # them together, multiplied by a strength. We will have one for fleeing, and one for pursuing, # toggling them depending on the agent's health. Since we want the agent to rotate AND move, then # we aim to blend them together. -onready var flee_blend := GSAIBlend.new(agent) -onready var pursue_blend := GSAIBlend.new(agent) +var flee_blend : GSAIBlend = null +var pursue_blend : GSAIBlend = null # GSAIPriority will be the main steering behavior we use. It holds sub-behaviors and will pick the # first one that returns non-zero acceleration, ignoring any afterwards. -onready var priority := GSAIPriority.new(agent) +var priority : GSAIPriority = null func _ready() -> void: + acceleration = GSAITargetAcceleration.new() + agent = GSAISteeringAgent.new() + player = get_tree().get_nodes_in_group("Player")[0] + player_agent = player.agent + + proximity = GSAIRadiusProximity.new() + proximity.agent = agent + proximity.agents = [ player_agent ] + proximity.radius = 100 + + flee_blend = GSAIBlend.new() + flee_blend.agent = agent + + pursue_blend = GSAIBlend.new() + pursue_blend.agent = agent + + priority = GSAIPriority.new() + priority.agent = agent + # ---------- Configuration for our agent ---------- agent.linear_speed_max = speed_max agent.linear_acceleration_max = acceleration_max @@ -58,20 +77,28 @@ func _ready() -> void: # ---------- Configuration for our behaviors ---------- # Pursue will happen while the agent is in good health. It produces acceleration that takes # the agent on an intercept course with the target, predicting its position in the future. - var pursue := GSAIPursue.new(agent, player_agent) + var pursue : GSAIPursue = GSAIPursue.new() + pursue.agent = agent + pursue.target = player_agent pursue.predict_time_max = 1.5 # Flee will happen while the agent is in bad health, so will start disabled. It produces # acceleration that takes the agent directly away from the target with no prediction. - var flee := GSAIFlee.new(agent, player_agent) + var flee : GSAIFlee = GSAIFlee.new() + flee.agent = agent + flee.target = player_agent # AvoidCollision tries to keep the agent from running into any of the neighbors found in its # proximity group. In our case, this will be the player, if they are close enough. - var avoid := GSAIAvoidCollisions.new(agent, proximity) + var avoid : GSAIAvoidCollisions = GSAIAvoidCollisions.new() + avoid.agent = agent + avoid.proximity = proximity # Face turns the agent to keep looking towards its target. It will be enabled while the agent # is not fleeing due to low health. It tries to arrive 'on alignment' with 0 remaining velocity. - var face := GSAIFace.new(agent, player_agent) + var face : GSAIFace = GSAIFace.new() + face.agent = agent + face.target = player_agent # We use deg2rad because the math in the toolkit assumes radians. # How close for the agent to be 'aligned', if not exact. @@ -81,7 +108,8 @@ func _ready() -> void: # LookWhereYouGo turns the agent to keep looking towards its direction of travel. It will only # be enabled while the agent is at low health. - var look := GSAILookWhereYouGo.new(agent) + var look : GSAILookWhereYouGo = GSAILookWhereYouGo.new() + look.agent = agent # How close for the agent to be 'aligned', if not exact look.alignment_tolerance = deg2rad(5) # When to start slowing down. diff --git a/godot/Demos/Quickstart/Player.gd b/godot/Demos/Quickstart/Player.gd index 40bcc4c..3a97a1e 100644 --- a/godot/Demos/Quickstart/Player.gd +++ b/godot/Demos/Quickstart/Player.gd @@ -10,14 +10,21 @@ var velocity := Vector2.ZERO var angular_velocity := 0.0 var direction := Vector2.RIGHT -onready var agent := GSAISteeringAgent.new() -onready var proxy_target := GSAIAgentLocation.new() -onready var face := GSAIFace.new(agent, proxy_target) +var agent : GSAISteeringAgent = null +var proxy_target : GSAIAgentLocation = null +var face : GSAIFace = null + onready var accel := GSAITargetAcceleration.new() onready var bullets := owner.get_node("Bullets") func _ready() -> void: + agent = GSAISteeringAgent.new() + proxy_target = GSAIAgentLocation.new() + face = GSAIFace.new() + face.agent = agent + face.target = proxy_target + agent.linear_speed_max = speed_max agent.linear_acceleration_max = acceleration_max agent.angular_speed_max = deg2rad(rotation_speed_max) diff --git a/godot/Demos/SeekFlee/Seeker.gd b/godot/Demos/SeekFlee/Seeker.gd index e2252f3..e2927bd 100644 --- a/godot/Demos/SeekFlee/Seeker.gd +++ b/godot/Demos/SeekFlee/Seeker.gd @@ -6,13 +6,26 @@ var start_speed: float var start_accel: float var use_seek := true -onready var agent := GSAIKinematicBody2DAgent.new(self) -onready var accel := GSAITargetAcceleration.new() -onready var seek := GSAISeek.new(agent, player_agent) -onready var flee := GSAIFlee.new(agent, player_agent) +var agent : GSAIKinematicBody2DAgent = null +var accel : GSAITargetAcceleration = null +var seek : GSAISeek = null +var flee : GSAIFlee = null func _ready() -> void: + agent = GSAIKinematicBody2DAgent.new() + agent.body = self + + accel = GSAITargetAcceleration.new() + + seek = GSAISeek.new() + seek.agent = agent + seek.target = player_agent + + flee = GSAIFlee.new() + flee.agent = agent + flee.target = player_agent + agent.linear_acceleration_max = start_accel agent.linear_speed_max = start_speed 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 5d5f670..84f2a53 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 @@ -17,21 +17,12 @@ enum MovementType { var body: KinematicBody2D setget _set_body # The type of movement the body executes -var movement_type : int = 0 +var movement_type : int = MovementType.SLIDE var _last_position : Vector2 var _body_ref : WeakRef -func _init(_body: KinematicBody2D, _movement_type: int = MovementType.SLIDE) -> void: - self.body = _body - self.movement_type = _movement_type - - if !_body.is_inside_tree(): - _body.connect("ready", self, "_body_ready") - else: - _body_ready() - func _body_ready() -> void: # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") @@ -122,6 +113,11 @@ func _apply_orientation_steering(angular_acceleration: float, delta: float) -> v func _set_body(value: KinematicBody2D) -> void: + var had_body : bool = false + + if body: + had_body = true + body = value _body_ref = weakref(body) @@ -130,6 +126,12 @@ func _set_body(value: KinematicBody2D) -> void: position = GSAIUtils.to_vector3(_last_position) orientation = _last_orientation + + if !had_body: + if !body.is_inside_tree(): + body.connect("ready", self, "_body_ready") + else: + _body_ready() func _on_SceneTree_physics_frame() -> void: 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 9f8474d..0b0700e 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 @@ -23,15 +23,6 @@ var _last_position : Vector3 var _body_ref : WeakRef -func _init(_body: KinematicBody, _movement_type: int = MovementType.SLIDE) -> void: - self.body = _body - self.movement_type = _movement_type - - if !_body.is_inside_tree(): - _body.connect("ready", self, "_body_ready") - else: - _body_ready() - func _body_ready() -> void: # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_physics_frame") @@ -115,6 +106,11 @@ func _apply_orientation_steering(angular_acceleration: float, delta: float) -> v func _set_body(value: KinematicBody) -> void: + var had_body : bool = false + + if body: + had_body = true + body = value _body_ref = weakref(value) @@ -124,6 +120,11 @@ func _set_body(value: KinematicBody) -> void: position = _last_position orientation = _last_orientation + if !had_body: + if !body.is_inside_tree(): + body.connect("ready", self, "_body_ready") + else: + _body_ready() func _on_SceneTree_physics_frame() -> void: var _body : KinematicBody = _body_ref.get_ref() 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 4eb71bb..c4726db 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 @@ -11,14 +11,6 @@ var _last_position : Vector2 var _body_ref : WeakRef -func _init(_body : RigidBody2D) -> void: - self.body = _body - - if !_body.is_inside_tree(): - _body.connect("ready", self, "_body_ready") - else: - _body_ready() - func _body_ready() -> void: # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") @@ -40,6 +32,11 @@ func _apply_steering(acceleration : GSAITargetAcceleration, _delta : float) -> v func _set_body(value: RigidBody2D) -> void: + var had_body : bool = false + + if body: + had_body = true + body = value _body_ref = weakref(value) @@ -48,6 +45,12 @@ func _set_body(value: RigidBody2D) -> void: position = GSAIUtils.to_vector3(_last_position) orientation = _last_orientation + + if !had_body: + if !body.is_inside_tree(): + body.connect("ready", self, "_body_ready") + else: + _body_ready() func _on_SceneTree_frame() -> void: 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 b5ba8b8..456af46 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 @@ -10,14 +10,6 @@ var body: RigidBody setget _set_body var _last_position: Vector3 var _body_ref: WeakRef -func _init(_body: RigidBody) -> void: - self.body = _body - - if !_body.is_inside_tree(): - _body.connect("ready", self, "_body_ready") - else: - _body_ready() - func _body_ready() -> void: # warning-ignore:return_value_discarded body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame") @@ -39,6 +31,11 @@ func _apply_steering(acceleration: GSAITargetAcceleration, _delta: float) -> voi func _set_body(value: RigidBody) -> void: + var had_body : bool = false + + if body: + had_body = true + body = value _body_ref = weakref(value) @@ -47,7 +44,12 @@ func _set_body(value: RigidBody) -> void: position = _last_position orientation = _last_orientation - + + if !had_body: + if !body.is_inside_tree(): + body.connect("ready", self, "_body_ready") + else: + _body_ready() func _on_SceneTree_frame() -> void: var _body: RigidBody = _body_ref.get_ref() diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIArrive.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIArrive.gd index 4dafa5b..6653ac0 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIArrive.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIArrive.gd @@ -15,10 +15,6 @@ var deceleration_radius : float = 0.0 var time_to_reach : float = 0.1 -func _init(agent : GSAISteeringAgent, _target : GSAIAgentLocation).(agent) -> void: - self.target = _target - - func _arrive(acceleration : GSAITargetAcceleration, target_position : Vector3) -> void: var to_target : Vector3 = target_position - agent.position var distance : float = to_target.length() diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIAvoidCollisions.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIAvoidCollisions.gd index f3043db..dbf11ed 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIAvoidCollisions.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIAvoidCollisions.gd @@ -12,10 +12,6 @@ var _first_relative_position : Vector3 var _first_relative_velocity : Vector3 -func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity) -> void: - pass - - func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: _shortest_time = INF _first_neighbor = null diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIBlend.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIBlend.gd index fde2ff2..8f3306b 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIBlend.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIBlend.gd @@ -13,11 +13,6 @@ extends GSAISteeringBehavior var _behaviors : Array = Array() var _accel : GSAITargetAcceleration = GSAITargetAcceleration.new() - -func _init(agent : GSAISteeringAgent).(agent) -> void: - pass - - # Appends a behavior to the internal array along with its `weight`. func add(behavior : GSAISteeringBehavior, weight : float) -> void: behavior.agent = agent diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAICohesion.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAICohesion.gd index 48441c0..4767529 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAICohesion.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAICohesion.gd @@ -7,10 +7,6 @@ extends GSAIGroupBehavior var _center_of_mass: Vector3 -func _init(agent: GSAISteeringAgent, proximity: GSAIProximity).(agent, proximity) -> void: - pass - - func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: acceleration.set_zero() _center_of_mass = Vector3.ZERO diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIEvade.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIEvade.gd index 0a73b56..6fe2468 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIEvade.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIEvade.gd @@ -5,9 +5,5 @@ class_name GSAIEvade extends GSAIPursue -func _init(agent: GSAISteeringAgent, target: GSAISteeringAgent, predict_time_max : float = 1.0).(agent, target, predict_time_max): - pass - - func _get_modified_acceleration() -> float: return -agent.linear_acceleration_max diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFace.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFace.gd index 95abebb..fbacc8f 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFace.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFace.gd @@ -5,9 +5,6 @@ class_name GSAIFace extends GSAIMatchOrientation -func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation, use_z := false).(agent, target, use_z) -> void: - pass - func _face(acceleration: GSAITargetAcceleration, target_position: Vector3) -> void: var to_target : Vector3 = target_position - agent.position var distance_squared : float = to_target.length_squared() diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFlee.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFlee.gd index b489051..4d763fa 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFlee.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFlee.gd @@ -4,10 +4,6 @@ class_name GSAIFlee extends GSAISeek -func _init(agent: GSAISteeringAgent, target: GSAIAgentLocation).(agent, target) -> void: - pass - - func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: acceleration.linear = ((agent.position - target.position).normalized() * agent.linear_acceleration_max) acceleration.angular = 0 diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFollowPath.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFollowPath.gd index 609fc26..8c77e0a 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFollowPath.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIFollowPath.gd @@ -15,12 +15,6 @@ var is_arrive_enabled : bool = true var prediction_time : float = 0.0 -func _init(agent: GSAISteeringAgent, _path: GSAIPath, _path_offset := 0.0, _prediction_time := 0.0).(agent, null) -> void: - self.path = _path - self.path_offset = _path_offset - self.prediction_time = _prediction_time - - func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: var location : Vector3 diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAILookWhereYouGo.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAILookWhereYouGo.gd index 7d05d65..ca644e4 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAILookWhereYouGo.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAILookWhereYouGo.gd @@ -5,10 +5,6 @@ class_name GSAILookWhereYouGo extends GSAIMatchOrientation -func _init(agent: GSAISteeringAgent, use_z : bool = false).(agent, null, use_z) -> void: - pass - - func _calculate_steering(accel: GSAITargetAcceleration) -> void: if agent.linear_velocity.length_squared() < agent.zero_linear_speed_threshold: accel.set_zero() diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIMatchOrientation.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIMatchOrientation.gd index 68e447a..0811638 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIMatchOrientation.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIMatchOrientation.gd @@ -19,11 +19,6 @@ var time_to_reach : float = 0.1 var use_z : bool = false -func _init(agent: GSAISteeringAgent, _target: GSAIAgentLocation, _use_z : bool = false).(agent) -> void: - self.use_z = _use_z - self.target = _target - - func _match_orientation(acceleration: GSAITargetAcceleration, desired_orientation: float) -> void: var rotation : float = wrapf(desired_orientation - agent.orientation, -PI, PI) 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 deee85e..20adb93 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 @@ -7,16 +7,12 @@ extends GSAISteeringBehavior var _behaviors : Array = Array() # The index of the last behavior the container prioritized. -var last_selected_index : int = 0 +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 -func _init(agent: GSAISteeringAgent, _zero_threshold : float = 0.001).(agent) -> void: - self.zero_threshold = _zero_threshold - - # Appends a steering behavior as a child of this container. func add(behavior: GSAISteeringBehavior) -> void: _behaviors.append(behavior) @@ -36,13 +32,13 @@ func get_behavior_at(index : int) -> GSAISteeringBehavior: func _calculate_steering(accel : GSAITargetAcceleration) -> void: var threshold_squared : float = zero_threshold * zero_threshold - last_selected_index = -1 + _last_selected_index = -1 var size : int = _behaviors.size() if size > 0: for i in range(size): - last_selected_index = i + _last_selected_index = i var behavior: GSAISteeringBehavior = _behaviors[i] behavior.calculate_steering(accel) diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPursue.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPursue.gd index 7219dac..da5cd05 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPursue.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAIPursue.gd @@ -8,13 +8,7 @@ extends GSAISteeringBehavior var target : GSAISteeringAgent # The maximum amount of time in the future the behavior predicts the target's # location. -var predict_time_max : float = 0 - - -func _init(agent : GSAISteeringAgent, _target : GSAISteeringAgent, _predict_time_max : float = 1.0).(agent) -> void: - self.target = _target - self.predict_time_max = _predict_time_max - +var predict_time_max : float = 1.0 func _calculate_steering(acceleration : GSAITargetAcceleration) -> void: var target_position : Vector3 = target.position diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeek.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeek.gd index 3996929..67df445 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeek.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeek.gd @@ -8,10 +8,6 @@ extends GSAISteeringBehavior var target : GSAIAgentLocation -func _init(agent : GSAISteeringAgent, _target : GSAIAgentLocation).(agent) -> void: - self.target = _target - - func _calculate_steering(acceleration: GSAITargetAcceleration) -> void: acceleration.linear = ((target.position - agent.position).normalized() * agent.linear_acceleration_max) acceleration.angular = 0 diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeparation.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeparation.gd index 4e455b8..4a0e1d5 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeparation.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Behaviors/GSAISeparation.gd @@ -14,10 +14,6 @@ var decay_coefficient : float = 1.0 var _acceleration : GSAITargetAcceleration -func _init(agent : GSAISteeringAgent, proximity : GSAIProximity).(agent, proximity) -> void: - pass - - func _calculate_steering(acceleration : GSAITargetAcceleration) -> void: acceleration.set_zero() self._acceleration = acceleration diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIGroupBehavior.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIGroupBehavior.gd index f9e21b8..9437a4b 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIGroupBehavior.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIGroupBehavior.gd @@ -9,10 +9,6 @@ var proximity : GSAIProximity var _callback : FuncRef = funcref(self, "_report_neighbor") -func _init(agent : GSAISteeringAgent, _proximity : GSAIProximity).(agent) -> void: - self.proximity = _proximity - - # Internal callback for the behavior to define whether or not a member is # relevant # @tags - virtual 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 ce35384..8b77d71 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAIPath.gd @@ -15,7 +15,7 @@ var _nearest_point_on_segment : Vector3 var _nearest_point_on_path : Vector3 -func _init(waypoints : Array, _is_open : bool = false) -> void: +func initialize(waypoints : Array, _is_open : bool = false) -> void: self.is_open = _is_open create_path(waypoints) _nearest_point_on_segment = waypoints[0] @@ -115,7 +115,7 @@ func _calculate_point_segment_distance_squared(start: Vector3, end: Vector3, pos return _nearest_point_on_segment.distance_squared_to(position) - +# not exposed helper struct class GSAISegment: var begin: Vector3 var end: Vector3 diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAISteeringBehavior.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAISteeringBehavior.gd index 382ccc4..aa31863 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/GSAISteeringBehavior.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/GSAISteeringBehavior.gd @@ -14,11 +14,6 @@ var is_enabled : bool = true # The AI agent on which the steering behavior bases its calculations. var agent : GSAISteeringAgent - -func _init(_agent: GSAISteeringAgent) -> void: - agent = _agent - - # Sets the `acceleration` with the behavior's desired amount of acceleration. func calculate_steering(acceleration: GSAITargetAcceleration) -> void: if is_enabled: diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIInfiniteProximity.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIInfiniteProximity.gd index 05c27bd..fd5ca7c 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIInfiniteProximity.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIInfiniteProximity.gd @@ -5,10 +5,6 @@ extends GSAIProximity class_name GSAIInfiniteProximity -func _init(agent: GSAISteeringAgent, agents: Array).(agent, agents) -> void: - pass - - # Returns a number of neighbors based on a `callback` function. # # `_find_neighbors` calls `callback` for each agent in the `agents` array and diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIProximity.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIProximity.gd index bef7a45..16395f4 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIProximity.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIProximity.gd @@ -10,11 +10,6 @@ var agent : GSAISteeringAgent var agents : Array = Array() -func _init(_agent: GSAISteeringAgent, _agents: Array) -> void: - self.agent = _agent - self.agents = _agents - - # Returns a number of neighbors based on a `callback` function. # # `_find_neighbors` calls `callback` for each agent in the `agents` array and diff --git a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIRadiusProximity.gd b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIRadiusProximity.gd index edf8ff3..3a97262 100644 --- a/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIRadiusProximity.gd +++ b/godot/addons/com.gdquest.godot-steering-ai-framework/Proximities/GSAIRadiusProximity.gd @@ -11,11 +11,9 @@ var _last_frame : int = 0 var _scene_tree : SceneTree -func _init(agent: GSAISteeringAgent, agents: Array, _radius: float).(agent, agents) -> void: - self.radius = _radius +func _init() -> void: _scene_tree = Engine.get_main_loop() - # Returns a number of neighbors based on a `callback` function. # # `_find_neighbors` calls `callback` for each agent in the `agents` array that lie within