The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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!

in Engine by (39 points)

2 Answers

0 votes

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.

by (10,634 points)
0 votes

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

Now go to your enemy scene, select Area2D node and connect signal body_entered(body : Node)

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
by (753 points)

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?

you have to connect signal, make sure that signals are connected
if its working on spikes then it should also work on enemy.

can you show your enemy scene?

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.