I create a spike obstacle under the platform and when player interact with spikes fall down to the player. for this a make a_on_area_entered signal and a collision for detect player but when i run its not working and there is no error. even i added a print function to check is there any detection player and obstacle, but there is no output on console.
#cant activate animation when player interact with obstacles
18 messages · Page 1 of 1 (latest)
could be that Player isnt a name? maybe try putting "" around it?
also, you get an area2d when asking for that function
so you'd prolly want to use get_overlapping_bodies()
its either area.name == "Player" or
its body_entered and if body is Player
hmmm i can only see these functions for the area2d
might want to do this though to make things easier+
Player and spikes:
area.name == "Player" i use this too
Likely theres something wrong here. The players and spikes shouldnt have the same collisionlayer.
There's probably a few things you need to fix
- Make sure your player is a characterbody with a collision shape set to it.
- Your player's characterbody collision layer is set to LayerX (x can be anything). Right click that layer and name it "player" for your own reference
- Your spike detection area needs to have its MASK set to Layer X (player) to DETECT FOR player as a characterbody entering
- For the spike detection area, setup the signal for "body_entered" and connect it to a callable (e.g. "_on_body_entered")
the code on you spike detecion should look like
func _on_body_entered(other_body: Node2D) -> void:
if other_body.name == "Player": #Actually not necessary if you only have 1 node on CollisionLayerX
print("player entered")
#whatever other callables you want to happen
its working thank you
@export var animation_player : AnimationPlayer
func _on_body_entered(body):
if body.name == "Player":
animation_player.play("fall")
print("player in!")
spike:
player:
this is all fixed files for who needs like me
thx again