The Player won't pick up forages, when forages' layer mask is 3rd, instead of 1st

Godot Version

4.3

Question

I figured out that when forage’s collision layer is 1st, the player will take damage by skeleton, when it passed forage’s collision. But when I change forage’s collision layer to 3rd, the player can’t pick up any forages, because it’ll ignore that. Even I added 3rd collision layer to the tilemap. I think I messed up… anyway, there’s any solutions?

Screenshots

Godot_v4.2.2-stable_win64_6bC8523FgR
Godot_v4.2.2-stable_win64_SjluZ4J9h3


Godot_v4.3-stable_win64_hHm6JMO8tp
Godot_v4.3-stable_win64_lGeokJzxoc
Godot_v4.3-stable_win64_5bRJolqM7a

I think it would be best if you could define the layers first.

  • Layer 1: Player Layer
  • Layer 2: Enemy Layer
  • Layer 3: Item Layer

then define the Masks of the Player and the Enemy.
First of all, the Player should Mask the item and enemy layer, the enemy in turn should only mask the player layer. I don’t believe the items need to have to mask anything.

from the provided screenshots, I don’t have info of the player but I believe the player never differentiates what his area is colliding with?

func _on_player_hitbox_area_entered(_area):
    # check the area if it's an item or an enemy
    var object: String = get_origin(_area)
    if object == "Item": _current_area == _area

Of course this is just pseudocode but your _on_player_hitbox_area_entered can actually be triggered by an enemy or an item if your hitbox_area is masking both layers.
Either you have one area for each type or you need code to differentiate the entered_area’s origin.

I removed any masks from the forages’ Area2D and it works. That was soooo helpful. Thank you so much!

1 Like

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