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.

godotengine.org | Twitter

0 votes

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

Tl;DR
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?

in Engine by (20 points)

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. ;)

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. :)
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.)

1 Answer

0 votes

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 "playerhitbox" or "barrelhitbox") 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. 
    
by (137 points)

I Hope i undestanded your question well. :)

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.

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.