Hello, I’m using Area3Ds to make a PathFollow3D stop, then after a set number of enemies are kill, the PathFollow restart until the next Area3D.
However, only the first Area3D work correctly, and the next ones are ignored. Did I forget something, or my code work only once?
Here the code for the Area3D:
extends Area3D
@export var enemyNumber = 0
@export var pathFollow = PathFollow3D
func _physics_process(delta: float) -> void:
if enemyNumber <= 0:
pathFollow.progression = true
print(enemyNumber)
func _on_body_entered(body: Node3D) -> void:
if body.is_in_group("player") and enemyNumber > 0:
pathFollow.progression = false
The code for the enemies connected to the Area3D:
extends StaticBody3D
@export var health = 2
@export var parentNode = Area3D
var callParentNode = true
func _process(delta: float) -> void:
if health < 1:
if callParentNode == true:
parentNode.enemyNumber -= 1
callParentNode = false
rotation.y += 180
await get_tree().create_timer(1).timeout
self.queue_free()
And just in case, the code for the PathFollow3D
extends PathFollow3D
var progression = true
func _process(delta: float) -> void:
if progression == true:
progress += 1 * delta
These declarations should be using : to declare type, not = though I’m unsure if that causes any failure
@export var pathFollow: PathFollow3D # type defined, no value defined
If you have a instantiated scene to start and use code to create the rest and you are using the editor to connect a signal from that instantiated scene then the code-created scenes will not have that same signal. Maybe it would help to show your scene tree and try to mention which nodes have which scripts.
Like I said, only the first Area3D work as intended (stop the pathFollow3D and restart when all the enemies associated (enemyNumber) are kill, thus enemyNumber = 0) and the next ones are ignored, instead of stopping at each one and having to kill all enemies to continue, like in a rail shooter.
For testing if it’s work, I use print() to see if enemyNumber decrease to 0, and if my area3D register my player node entering it, and both seem to work but my player still don’t stop
If you have more than one area assigning pathFollow.progression then it seems it will always be forced true, unless you change all of the Area3D’s enemyNumber to zero? Can you ensure the other Area3D have a greater than zero enemyNumber by the time they are reached?
I would try to remove the _physics_process on the Area3D, it doesn’t need to check constantly where a signal would do.