mirror of
https://github.com/Relintai/godot-steering-ai-framework.git
synced 2024-11-14 04:57:19 +01:00
Append _ to apply_steering and fix yield on ready
This commit is contained in:
parent
1baed58659
commit
dc9a57e7fd
@ -12,7 +12,7 @@ var _drag := 0.1
|
|||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
arrive.calculate_steering(_accel)
|
arrive.calculate_steering(_accel)
|
||||||
agent.apply_steering(_accel, delta)
|
agent._apply_steering(_accel, delta)
|
||||||
|
|
||||||
|
|
||||||
func setup(
|
func setup(
|
||||||
|
@ -31,7 +31,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
target.position.y = agent.position.y + _direction.y*_radius
|
target.position.y = agent.position.y + _direction.y*_radius
|
||||||
|
|
||||||
priority.calculate_steering(_accel)
|
priority.calculate_steering(_accel)
|
||||||
agent.apply_steering(_accel, delta)
|
agent._apply_steering(_accel, delta)
|
||||||
|
|
||||||
|
|
||||||
func setup(
|
func setup(
|
||||||
|
@ -20,7 +20,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
face.calculate_steering(_accel)
|
face.calculate_steering(_accel)
|
||||||
agent.apply_steering(_accel, delta)
|
agent._apply_steering(_accel, delta)
|
||||||
|
|
||||||
|
|
||||||
func _draw() -> void:
|
func _draw() -> void:
|
||||||
|
@ -36,7 +36,7 @@ func setup(
|
|||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if _valid:
|
if _valid:
|
||||||
follow.calculate_steering(_accel)
|
follow.calculate_steering(_accel)
|
||||||
agent.apply_steering(_accel, delta)
|
agent._apply_steering(_accel, delta)
|
||||||
|
|
||||||
|
|
||||||
func _on_Drawer_path_established(points: Array) -> void:
|
func _on_Drawer_path_established(points: Array) -> void:
|
||||||
|
@ -46,7 +46,7 @@ func _draw() -> void:
|
|||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if blend:
|
if blend:
|
||||||
blend.calculate_steering(acceleration)
|
blend.calculate_steering(acceleration)
|
||||||
agent.apply_steering(acceleration, delta)
|
agent._apply_steering(acceleration, delta)
|
||||||
|
|
||||||
|
|
||||||
func set_neighbors(neighbor: Array) -> void:
|
func set_neighbors(neighbor: Array) -> void:
|
||||||
|
@ -27,4 +27,4 @@ func _physics_process(delta: float) -> void:
|
|||||||
else:
|
else:
|
||||||
flee.calculate_steering(accel)
|
flee.calculate_steering(accel)
|
||||||
|
|
||||||
agent.apply_steering(accel, delta)
|
agent._apply_steering(accel, delta)
|
||||||
|
@ -153,6 +153,11 @@ _global_script_classes=[ {
|
|||||||
"class": "GSTUtils",
|
"class": "GSTUtils",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
"path": "res://src/GSTUtils.gd"
|
"path": "res://src/GSTUtils.gd"
|
||||||
|
}, {
|
||||||
|
"base": "EditorScript",
|
||||||
|
"class": "ReferenceCollector",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://ReferenceCollector.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
"GSTAgentLocation": "",
|
"GSTAgentLocation": "",
|
||||||
@ -183,7 +188,8 @@ _global_script_class_icons={
|
|||||||
"GSTSteeringAgent": "",
|
"GSTSteeringAgent": "",
|
||||||
"GSTSteeringBehavior": "",
|
"GSTSteeringBehavior": "",
|
||||||
"GSTTargetAcceleration": "",
|
"GSTTargetAcceleration": "",
|
||||||
"GSTUtils": ""
|
"GSTUtils": "",
|
||||||
|
"ReferenceCollector": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
[application]
|
[application]
|
||||||
|
@ -4,6 +4,9 @@ extends GSTSpecializedAgent
|
|||||||
class_name GSTKinematicBody2DAgent
|
class_name GSTKinematicBody2DAgent
|
||||||
|
|
||||||
|
|
||||||
|
# SLIDE uses `move_and_slide`
|
||||||
|
# COLLIDE uses `move_and_collide`
|
||||||
|
# POSITION changes the `global_position` directly
|
||||||
enum MovementType { SLIDE, COLLIDE, POSITION }
|
enum MovementType { SLIDE, COLLIDE, POSITION }
|
||||||
|
|
||||||
|
|
||||||
@ -11,17 +14,14 @@ enum MovementType { SLIDE, COLLIDE, POSITION }
|
|||||||
var body: KinematicBody2D setget _set_body
|
var body: KinematicBody2D setget _set_body
|
||||||
|
|
||||||
# The type of movement the body executes
|
# 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 movement_type: int
|
||||||
|
|
||||||
var _last_position: Vector2
|
var _last_position: Vector2
|
||||||
|
|
||||||
|
|
||||||
func _init(body: KinematicBody2D, movement_type: int = MovementType.SLIDE) -> void:
|
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.body = body
|
||||||
self.movement_type = movement_type
|
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`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
match movement_type:
|
match movement_type:
|
||||||
MovementType.COLLIDE:
|
MovementType.COLLIDE:
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
extends GSTSpecializedAgent
|
extends GSTSpecializedAgent
|
||||||
class_name GSTKinematicBodyAgent
|
class_name GSTKinematicBodyAgent
|
||||||
|
|
||||||
|
# SLIDE uses `move_and_slide`
|
||||||
|
# COLLIDE uses `move_and_collide`
|
||||||
|
# POSITION changes the global_position directly
|
||||||
enum MovementType { SLIDE, COLLIDE, POSITION }
|
enum MovementType { SLIDE, COLLIDE, POSITION }
|
||||||
|
|
||||||
|
|
||||||
@ -11,17 +13,14 @@ enum MovementType { SLIDE, COLLIDE, POSITION }
|
|||||||
var body: KinematicBody setget _set_body
|
var body: KinematicBody setget _set_body
|
||||||
|
|
||||||
# The type of movement the body executes
|
# 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 movement_type: int
|
||||||
|
|
||||||
var _last_position: Vector3
|
var _last_position: Vector3
|
||||||
|
|
||||||
|
|
||||||
func _init(body: KinematicBody, movement_type: int = MovementType.SLIDE) -> void:
|
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.body = body
|
||||||
self.movement_type = movement_type
|
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`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
match movement_type:
|
match movement_type:
|
||||||
MovementType.COLLIDE:
|
MovementType.COLLIDE:
|
||||||
|
@ -11,16 +11,15 @@ var _last_position: Vector2
|
|||||||
|
|
||||||
|
|
||||||
func _init(body: RigidBody2D) -> void:
|
func _init(body: RigidBody2D) -> void:
|
||||||
|
if not body.is_inside_tree():
|
||||||
|
yield(body, "ready")
|
||||||
|
|
||||||
self.body = body
|
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`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
body.apply_central_impulse(GSTUtils.to_vector2(acceleration.linear))
|
body.apply_central_impulse(GSTUtils.to_vector2(acceleration.linear))
|
||||||
body.apply_torque_impulse(acceleration.angular)
|
body.apply_torque_impulse(acceleration.angular)
|
||||||
|
@ -11,16 +11,17 @@ var _last_position: Vector3
|
|||||||
|
|
||||||
|
|
||||||
func _init(body: RigidBody) -> void:
|
func _init(body: RigidBody) -> void:
|
||||||
|
if not body.is_inside_tree():
|
||||||
|
yield(body, "ready")
|
||||||
|
|
||||||
self.body = body
|
self.body = body
|
||||||
if body.is_inside_tree():
|
body.get_tree().connect("physics_frame", self, "_on_SceneTree_frame")
|
||||||
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`.
|
# Moves the agent's `body` by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
||||||
_applied_steering = true
|
_applied_steering = true
|
||||||
body.apply_central_impulse(acceleration.linear)
|
body.apply_central_impulse(acceleration.linear)
|
||||||
body.apply_torque_impulse(Vector3.UP * acceleration.angular)
|
body.apply_torque_impulse(Vector3.UP * acceleration.angular)
|
||||||
|
@ -9,12 +9,12 @@ class_name GSTSpecializedAgent
|
|||||||
# frame. When `false`, the user must keep those values updated.
|
# frame. When `false`, the user must keep those values updated.
|
||||||
var calculate_velocities := true
|
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.
|
# the current linear velocity towards 0 by the `linear_drag_percentage` value.
|
||||||
# Does not apply to `RigidBody` and `RigidBody2D` nodes.
|
# Does not apply to `RigidBody` and `RigidBody2D` nodes.
|
||||||
var apply_linear_drag := true
|
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.
|
# the current angular velocity towards 0 by the `angular_drag_percentage` value.
|
||||||
# Does not apply to `RigidBody` and `RigidBody2D` nodes.
|
# Does not apply to `RigidBody` and `RigidBody2D` nodes.
|
||||||
var apply_angular_drag := true
|
var apply_angular_drag := true
|
||||||
@ -36,5 +36,5 @@ var _applied_steering := false
|
|||||||
|
|
||||||
# Moves the agent's body by target `acceleration`.
|
# Moves the agent's body by target `acceleration`.
|
||||||
# tags: virtual
|
# tags: virtual
|
||||||
func apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
func _apply_steering(acceleration: GSTTargetAcceleration, delta: float) -> void:
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user