Append _ to apply_steering and fix yield on ready

This commit is contained in:
Francois Belair 2020-02-07 09:15:03 -05:00
parent 1baed58659
commit dc9a57e7fd
12 changed files with 38 additions and 33 deletions

View File

@ -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(

View File

@ -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(

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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]

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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