This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello. I am making a 2d platformer where there is an enemy. My enemy is an area 2d it moves left and right. If the player touches the player takes damage but when a bullet touches it dies. the names of my player and bullet scene is "Player" and "Bullet" respectively.(just a note my bullet is an area 2d)

so here is my code for detection of player and the bullet

func _on_Area2D_body_entered(body):
if body.get_name() == "Bullet":
    queue_free()
if body.get_name() == "Player":
    get_tree().reload_current_scene()

however, my bullet does not disappear after hitting my enemy and my player is also going through the enemy without reloading the scene.

bullet collision layer 2 mask 2
enemy collision layer 1&2 mask 1&2
player collision layer 1 mask 1

so how should I do this?

Godot version v3.4.4
in Engine by (32 points)

1 Answer

0 votes

Assuming the function is in your enemy script, you only call queue_free for the enemy, not for the bullet. And have checked that PhysicsBody2D node of the player scene is actually named "Player"?

by (104 points)

I checked and the kinematicbody2d node of the player was spelled wrongly causing the issue, however, it still does not work. My bullet disappears when it hits anything but for some reason nothing is happening. How should I go about this??? and just a question is an area 2d considered a body?

No, Area2D is not a body. Body2D refers to KinematicBody2D, RigidBody2D or StaticBody2D. If you need to detect another Area2D, you should use area_entered(area) and if you need to detect a body node, use body_entered(body). See docs.

Thanks so much :)

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.