Topic was automatically imported from the old Question2Answer platform.
Asked By
TraitPhoe
I making some 2D platformer and stoped on one problem:death. Im need to make that i touching the enemy,and then die. Would be better,if i receive not only an answer, but also an explanation. Already thanks!
I recommend you work through this tutorial, specifically this part. If you have any specific questions, feel free to ask them here and I’ll go into more detail.
For your enemy add Area2d node and then add CollisionShape2D to Area2D and set a shape of your choice. Area2D can detect object entered its area.
For your player use KinematicBody2D and set its shape.
Then add your player to group player image
Now go to your enemy scene, select Area2D node and connect signal body_entered(body : Node) image
Then use this code
#this function is called when any body enters this area
func _on_Area2D_body_entered(body):
#confirm that the body is player
if body.is_in_group("player"):
#call kill , assuming that you have defined kill function for player
body.kill()
I tried by you method but nothing. When i jumping on enemy nothing is happening,but on spikes,that i set and gave them Area2D node its worked. Any ideas?
TraitPhoe | 2020-04-09 11:51
you have to connect signal, make sure that signals are connected
if its working on spikes then it should also work on enemy.