Hitbox 2D Fighting Game

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

THIS IS ENEMY

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
pass

Thanks for answers…

:bust_in_silhouette: Reply From: i_love_godot

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 :slight_smile:

Finite State Machine
Raycast2D
Area2D

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

fpicoral | 2019-01-27 13:52

:bust_in_silhouette: Reply From: LordViperion

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.