How do i make a destructible item

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AwYiss

Ok so basically my game has this barrel that plays the destruction animation then the collision stays the same and when the player walks through the collision it will despawn and add player health the problem is how do i make it so it spawns at random locations and when player Attack hitbox overlap with the barrels collision it plays the animation with a delay of 2 seconds any code that sees if the hitbox is overlapped but only by the players attack hitbox?Also sorry for the bad wordings of some of this sentences i cant seem to describe this stuff would

OK so the player plays an animation if i press the right click button and that animation has a collision box how do i make it so any kinematicbody that collides with only this one
collision subtracts their overall health?

sorry for the bad wordings of some of this sentences i cant seem to describe this stuff would

Do what I do: proof read it. :wink:

Ertain | 2020-05-14 15:36

Next time you ask a qouestion, please try to separate topics a bit more, so the text doesn’t look that scary, because it’s more divided. :slight_smile:
So as I understand the qouestion is:
How to make a collider, that only collides with the player?
(So I’ll try my best answering, since I barely started too.)

Czselu349 | 2020-05-15 06:53

:bust_in_silhouette: Reply From: Czselu349

I work in 2D, but if you’re using 3D I think you can pretty much do the same logic.

  1. aproach:
    You can use the collision layers for detecting collisions with only a certain object type. If you’re using kinematicbody2D or a RigidBody2D then you can see at the properties, that it inherits from the so called “PhysicsBody2D” and there you can just add collisions to layers and be okay with that. (But I don’t really know enough of them to teach you how do they work, but you can find pretty good tutorials if you type in “collision layers godot”)
  2. aproach: (It may lead to spaggeti code, but i prefer this one.)
    You can make it with a collision-shape2D/polygon2D attached to area2D and it’s signals. (you need an Area2D both for the player and the barrel, What i do for prepare is put the collision shapes into groups with the name of “player_hitbox” or “barrel_hitbox”) like this: (if you do the code inside of the barrel)
    (BarrelHitbox could be the name of your collision shape2D)
    func _on_BarrelHitbox_area_entered(area):  
      if area.is_in_group("player_hitbox"):
         area.get_parent().current_health -= damage_of_the_barrel
         # This function can get the area wich you're colliding 
         # with. If you want to reduce the_player's health just get
         # the parent. 

I Hope i undestanded your question well. :slight_smile:

Czselu349 | 2020-05-15 08:07

Ok thank you for this information and i will word it better next time as i am also new to this engine and forum site so please forgive me for that question.

AwYiss | 2020-05-15 10:59