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 have another character and throw punch like that...

The problem is i already set health ready func but how can i implement hitbox
and give damage from player to enemy. For example jab give 5 damage and take from enemy's health etc.

How can i build this algorithm any instructions out there or documentation ?

func _ready():
var health = 30
# Called when the node is added to the scene for the first time.
# Initialization here

Thanks for answers...

in Engine by (12 points)

2 Answers

0 votes

I don't know if it is the best way, but I would use RayCast2D and Area2D nodes. Create Area2D nodes for the players' bodies, then have RayCast2D nodes that reach as long as a player's arm when they are punching. Using a state machine, if the player is_punching and the raycast is colliding, then you know that the player has "hit" the other player. Then just minus 5 from the health.

Hope this helps :)

Finite State Machine

by (384 points)

I would also recommend seeing the tutorial from KidsCanCode on youtube (the tank down kne). I learned a lot about health and other stuff there

0 votes

Use another collider box names would be damagebox. And damagebox only should be colliding with a hitbox,you need to set collisionlayer,mask for this. And if colliding is happen then subtract health var.

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