+1 vote

as the title says what I want to achieve is: eliminate a staticbody2d that fulfills the function of wall / wall within my game, eliminate it when another object which is a kinematicbody2d that fulfills the role of a missile hits it; the main problem I have is how to detect the collision in the staticbody2d. It should be noted that the layers and masks are configured perfectly

Godot version 3.2.3
in Engine by (44 points)
recategorized by

1 Answer

+1 vote
Best answer

The technique I used to accomplish this should be applicable to this situation:

Firstly, you want to make sure that your staticbody2D is actually an Area2D. This is because the Area2D node has the signal, "body_entered," which we will be using to detect collisions.

After creating an Area2D node, create a collisionshape2D that will serve as the "hitbox" of your wall, for your case it should cover the wall entirely I assume.

Connect the "body_entered" signal from Area2D to the script of your choosing.

func _on_Area2D_body_entered(body): 
    #Anything you want to happen before the wall is gone above queue_free()

To specify the kinematicbody2D, you can do the following:

func _on_Area2D_body_entered(body): 
    if body == "Missile":
by (51 points)
selected by

sorry if my english is so bad, thanks for your answer, but if i change the type of my staticbody2d, lost the property for collide with my player, this like say that the function of be a wall lost and i dont want that lost this function

In that case, here is a step-by-step solution:

  1. Create an Area2D
  2. Add a StaticBody2D as a child of Area2D
  3. Add a CollisionShape2D as a child of the StaticBody2D
  4. Add a CollisionShape2D as a child of Area2D

Now, it should have the functionality of the wall as well as be destructible using the code above.

exactly, i had not thought of it , thank you for the solution brou

Of course! Good luck and happy developing :)

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.