diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index 5991e6c1aed0888bd5f1e33cb8ec87f59d387dd1..ab9d808b2e2c65daf609280e8c3d6a4abbdb1946 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -53,7 +53,9 @@ onready var primaryHitArea:Area = $primaryHitArea var primaryAttackDmg:float = 15.0 var primaryAttackDist:float = 1.2 var primaryAttackDuration:float = 0.4 +# General direction (normalized anyway) var primaryAttackDirection:Vector3 = Vector3(3,1,0) +# Strength of the attack (multiply the normalized vector) var primaryAttackStrength:float = 1.5 # Secondary attack parameters @@ -212,9 +214,16 @@ func secondaryAttack(): # Called when detected by an attack's hitbox func hurt(damages:int, sourceId:int, direction:Vector3, strength:float): + # Add damages to your bar hp += damages + + # Projection: normalized vector * direction * strength added to the velocity of the player vel += strength*hp*direction + + # Update the last played who hit you lastStrikerId = sourceId + + # Feedback on the player's client rpc_unreliable_id(ownId, "hurt", hp) func die(): @@ -224,23 +233,29 @@ func die(): ######## SIGNALS ######## -# Primary hit has landed on something -func _on_primaryHitArea_body_entered(body:Node): - var direction:Vector3 = primaryAttackDirection.normalized() - direction.x*=bodyRotation +# General function on attack's hitboxes +func _on_generalHitArea_entered(damageVar:int, directionVar:Vector3, strengthVar:float, body:Node): + # Don't hurt yourself if int(body.name)==ownId: return + + # Normalized projection vector + var direction:Vector3 = directionVar.normalized() + + # Rotate the vector depending on the player orientation + direction.x*=bodyRotation print("body named " + body.name + " hit: primary") - body.hurt(primaryAttackDmg, ownId, direction, primaryAttackStrength) + + # Call the function on the affected player + body.hurt(damageVar, ownId, direction, strengthVar) + + +# Primary hit has landed on something +func _on_primaryHitArea_body_entered(body:Node): + _on_generalHitArea_entered(primaryAttackDmg, primaryAttackDirection, primaryAttackStrength, body) # Secondary hit has landed on something func _on_secondaryHitArea_body_entered(body:Node): - var direction:Vector3 = secondaryAttackDirection.normalized() - direction.x*=bodyRotation - if int(body.name)==ownId: - return - - print("body named " + body.name + " hit: secondary") - body.hurt(secondaryAttackDmg, ownId, direction, secondaryAttackStrength) + _on_generalHitArea_entered(secondaryAttackDmg, secondaryAttackDirection, secondaryAttackStrength, body)