Godot Version
4.1.1
Question
Here’s what I’ve got:
Player is a CharacterBody2D. I’ve successfully got them moving, colliding with level boundaries and not moving through them. Great.
I want players to be able to “use” certain objects that are in front of them, and probably highlight those objects when they’re within “use” range even before the user presses the use key. I’ve tried to do this with an Area2D (“UseActionArea”) that’s a child of Player, with its Monitoring set to true. Its CollisionShape2D is the one you can see extending out from the player.
I’ve set the mask on that Area2D to all 16 layers, though for the time being I only have one layer anyway, that includes the players’ own collision volumes and the level boundaries.
My code looks like this:
func _process(_delta):
# ...
# (movement handling etc)
# ...
if Input.is_action_pressed(_useAction):
print($UseActionArea.get_overlapping_areas().size())
I would expect that when my player is facing another player, or a wall, and they press their use key, this should print more than zero because it should pick up the player collision objects or the StaticBody2D (and its CollisionShape2Ds) that make up the level boundary. But it doesn’t. Huh? How come?
I’ve also tried adding signal handlers (adding this code to the bottom of my init function), and they don’t fire either:
$UseActionArea.body_entered.connect(onBodyEntered)
$UseActionArea.area_entered.connect(onAreaEntered)
func onBodyEntered():
print("BodyEntered")
func onAreaEntered():
print("Area entered")