Godot Version
4.2.1
Question
Hello fellow Godoteers! I’m working on a 3D game where I have a vehicle that should trigger a zombie spawner when it enters a specific Area3D. However, the vehicle is not triggering the body_entered
signal of the Area3D node, and I can’t seem to figure out why.
Here’s an overview of my setup:
- I have a
Zombie_Spawner_Area3D
node (an Area3D) positioned on the road where I want the vehicle to trigger the zombie spawner. - The
Zombie_Spawner_Area3D
has aCollisionShape3D
child node with aBoxShape3D
shape that covers a slice of the track. - The vehicle is a player controlled
Vehicle
node (a RigidBody3D) - I have a script attached to the
Zombie_Spawner_Area3D
node (Zombie_Spawner_Area3D.gd
) that should handle thebody_entered
signal when the vehicle enters the area.
Here’s the relevant code from the Zombie_Spawner_Area3D.gd
script:
extends Area3D
@onready var vehicle = $"../Vehicle/vehicle"
signal vehicle_entered_zombie_spawner
func _ready():
print("zombie spawner area 3d script ready")
body_entered.connect(_on_body_entered)
func _on_body_entered(body):
print("_on_body_entered called with body: ", body)
if body == vehicle:
print("Vehicle entered the area")
emit_signal("vehicle_entered_zombie_spawner")
else:
print("Body entered, but not the vehicle")
I’ve tried the following steps to troubleshoot the issue:
- Double-checked the collision layers and masks. The vehicle’s collision layer is set to 3, and the
Zombie_Spawner_Area3D
’s collision mask is set to 8 - Verified that the
Zombie_Spawner_Area3D
node and itsCollisionShape3D
child node are properly positioned and scaled to cover the desired area. - Ensured that the
Vehicle
node and its child nodes have the necessary collision shapes (CollisionShape3D
orCollisionPolygon3D
) to interact with theZombie_Spawner_Area3D
. - Checked that the signal connection is properly set up in the
Zombie_Spawner_Area3D.gd
script and that the_on_body_entered
function is connected to thebody_entered
signal. - Added print statements in the
_on_body_entered
function to track if the function is being called, but they never get triggered.
I’ve also tried adding print statements in the vehicle’s script to track its position and visualized the collision shapes during gameplay, but the vehicle seems to be moving correctly and passing through the Zombie_Spawner_Area3D
area.
Despite these efforts, the _on_body_entered
function is never called when the vehicle enters the area.
I would greatly appreciate any insights, suggestions, or possible solutions from the community to help me resolve this issue. Let me know if you need any additional information or code snippets.
Thank you in advance for your assistance! Cheers!