RigidBody3D not triggering body_entered on Area3D

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 a CollisionShape3D child node with a BoxShape3D 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 the body_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:

  1. 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
  2. Verified that the Zombie_Spawner_Area3D node and its CollisionShape3D child node are properly positioned and scaled to cover the desired area.
  3. Ensured that the Vehicle node and its child nodes have the necessary collision shapes (CollisionShape3D or CollisionPolygon3D) to interact with the Zombie_Spawner_Area3D.
  4. 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 the body_entered signal.
  5. 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!

As with me, you probably come from Unity, where layers are numbers (1 to 32) and layer masks are bitwise (1 << 0 to 1 << 31) . Which is probably why you set the layer to 3 and the mask to 8 (1 << 3)

In the Godot editor, they’re both numbers. Set the layers / mask both to 3 (or both to 8).
In code, however, both layers and masks are always bitwise so be careful!

Also, unlike Unity, Godot allows for an object to exist in several layers, since in the editor you can mark more than one :smiley:

Give that a shot, see if it fixes it.

1 Like

That was it! Thanks @Francis_IllogicGames!!! I am indeed a Unity refugee and was getting confused :joy:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.