From 2968be47f57221ff978525ef80c54cb50c1ac02d Mon Sep 17 00:00:00 2001 From: Adonis Stavridis <adonis-ioannis.stavridis@etu.unistra.fr> Date: Tue, 24 Mar 2020 18:02:56 +0100 Subject: [PATCH] #112 hitboxes fixed --- client/animations/kick_1.tres | 2 +- client/animations/punch_1.tres | 2 +- client/levels/test/game.gd | 10 +- server/autoloads/gamestate.gd | 2 +- server/entities/characters/Class1/class1.gd | 4 +- server/entities/characters/player.gd | 125 ++++++++++++-------- server/entities/characters/player.tscn | 17 +-- 7 files changed, 96 insertions(+), 66 deletions(-) diff --git a/client/animations/kick_1.tres b/client/animations/kick_1.tres index b7e098a..8c4759d 100644 --- a/client/animations/kick_1.tres +++ b/client/animations/kick_1.tres @@ -2,7 +2,7 @@ [resource] resource_name = "ArmatureAction" -length = 0.6 +length = 0.75 tracks/0/type = "transform" tracks/0/path = NodePath(".:belly_0") tracks/0/interp = 1 diff --git a/client/animations/punch_1.tres b/client/animations/punch_1.tres index ad7e236..d8643f3 100644 --- a/client/animations/punch_1.tres +++ b/client/animations/punch_1.tres @@ -2,7 +2,7 @@ [resource] resource_name = "ArmatureAction" -length = 0.55 +length = 0.6 tracks/0/type = "transform" tracks/0/path = NodePath(".:belly_0") tracks/0/interp = 1 diff --git a/client/levels/test/game.gd b/client/levels/test/game.gd index 2bb3e90..614d3e1 100644 --- a/client/levels/test/game.gd +++ b/client/levels/test/game.gd @@ -8,7 +8,11 @@ var jumpId:int = 0 # Distinguish 2 different jumps var sprintInput:bool = false # Attacks -enum {NONE=0, PRIMARY=1, SECONDARY=2} +enum { + NONE=0, + PUNCH=1, + KICK=2 +} func _physics_process(_delta): getPlayerInput() @@ -36,10 +40,10 @@ func getPlayerInput(): sprintInput = false if Input.is_action_pressed("primaryAttack"): - attackStateInput = PRIMARY + attackStateInput = PUNCH elif Input.is_action_pressed("secondaryAttack"): - attackStateInput = SECONDARY + attackStateInput = KICK # Sent without safety resend rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId, sprintInput, attackStateInput) diff --git a/server/autoloads/gamestate.gd b/server/autoloads/gamestate.gd index 12fa5c5..86335ac 100644 --- a/server/autoloads/gamestate.gd +++ b/server/autoloads/gamestate.gd @@ -3,7 +3,7 @@ extends Node const GAMEPATH = "/root/game/" const PORT = 10001 -const MAX_CLIENTS = 1 +const MAX_CLIENTS = 2 var players = {} diff --git a/server/entities/characters/Class1/class1.gd b/server/entities/characters/Class1/class1.gd index 8eaeed2..056b005 100644 --- a/server/entities/characters/Class1/class1.gd +++ b/server/entities/characters/Class1/class1.gd @@ -7,5 +7,5 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass \ No newline at end of file +# func _process(delta): +# pass diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index 25a3a4c..c1328c9 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -44,30 +44,44 @@ var isAttacking:bool = false onready var attackTimer:Tween = $attackTween # attack type -enum {NONE=0, PRIMARY=1, SECONDARY=2} +enum { + NONE = 0, + PUNCH = 1, + KICK = 2 +} +enum { + ID_PUNCH_1 = 0, + ID_PUNCH_2 = 1, + ID_KICK_1 = 2, + ID_KICK_2 = 3 +} var lastPunchId:int = 0 # Detect a new punch (of any type) -var idleTime:float = 0 # Stun when hitted + prevent spam - -# Primary attack parameters -onready var primaryHitArea:Area = $primaryHitArea -var primaryAttackDmg:float = 15.0 -var primaryAttackDist:float = 1.2 -var primaryAttackDuration:float = 0.5 +var idleTime:float = 0 # Stun when hit + prevent spam + +# Punch attack parameters +onready var punchHitArea:Area = $punchHitArea +var punchAttackDmg:float = 5.0 +var punchAttackDist:float = 0.5 +var punchAttackWait:float = 0.6 +var punch1AttackDuration:float = 0.1 +var punch2AttackDuration:float = 0.4 # General direction (normalized anyway) -var primaryAttackDirection:Vector3 = Vector3(3,1,0) +var punchAttackDirection:Vector3 = Vector3(1,1.5,0) # Strength of the attack (multiply the normalized vector) -var primaryAttackStrength:float = 1.5 - -# Secondary attack parameters -onready var secondaryHitArea:Area = $secondaryHitArea -var secondaryAttackDmg:float = 5.0 -var secondaryAttackDist:float = 1.2 -var secondaryAttackDuration:float = 0.5 -var secondaryAttackDirection:Vector3 = Vector3(1,5,0) -var secondaryAttackStrength:float = 0.8 +var punchAttackStrength:float = 0.5 + +# Punch 2 attack parameters +onready var kickHitArea:Area = $kickHitArea +var kickAttackDmg:float = 10.0 +var kickAttackDist:float = 0.9 +var kickAttackWait:float = 0.75 +var kick1AttackDuration:float = 0.2 +var kick2AttackDuration:float = 0.3 +var kickAttackDirection:Vector3 = Vector3(1.2,1,0) +var kickAttackStrength:float = 1 # Health points related values -var hp:float = 0.0 +var hp:int = 0 ######## ANIMATIONS ######## @@ -217,58 +231,69 @@ func processAttack(attackType:int): # Use the right function match attackType: - PRIMARY: - primaryAttack() + PUNCH: if self.is_on_floor(): if (!animSequence): broadcastAnimation(ANIM_PUNCH_1) animSequence = 1 + attack(ID_PUNCH_1) else: broadcastAnimation(ANIM_PUNCH_2) animSequence = 0 + attack(ID_PUNCH_2) else: broadcastAnimation(ANIM_JUMP_KICK_SIDE) - SECONDARY: - secondaryAttack() + KICK: if self.is_on_floor(): if (!animSequence): broadcastAnimation(ANIM_KICK_1) animSequence = 1 + attack(ID_KICK_1) else: broadcastAnimation(ANIM_KICK_2) animSequence = 0 + attack(ID_KICK_2) + +func attack(idAttack:int): + var hitArea:Area + var distance:float + var wait:float + var duration:float -func primaryAttack(): + if (idAttack == ID_PUNCH_1 || idAttack == ID_PUNCH_2): + hitArea = punchHitArea + distance = punchAttackDist + wait = punchAttackWait + if (idAttack == ID_PUNCH_1): + duration = punch1AttackDuration + else: + duration = punch2AttackDuration + else: + hitArea = kickHitArea + distance = kickAttackDist + wait = kickAttackWait + if (idAttack == ID_KICK_1): + duration = kick1AttackDuration + else: + duration = kick2AttackDuration + # Set active the hitbox of the attack, its visual feedback on server - primaryHitArea.set_monitoring(true) - primaryHitArea.set_visible(true) + hitArea.set_monitoring(true) + hitArea.set_visible(true) # Prepare the translation as an interpolation over time (end position, duration and function used) - attackTimer.interpolate_property(primaryHitArea, "translation:x", 0, primaryAttackDist, primaryAttackDuration, Tween.TRANS_LINEAR, Tween.EASE_IN) + attackTimer.interpolate_property(hitArea, "translation:x", 0, distance, duration, Tween.TRANS_LINEAR, Tween.EASE_OUT) attackTimer.start() - - # Once the movement is finished, turn off the hitbox and visual feedback yield(attackTimer, "tween_completed") - isAttacking = false - primaryHitArea.set_monitoring(false) - primaryHitArea.set_visible(false) - - -func secondaryAttack(): - # Set active the hitbox of the attack, its visual feedback on server - secondaryHitArea.set_monitoring(true) - secondaryHitArea.set_visible(true) - - # Prepare the translation as an interpolation over time (end position, duration and function used) - attackTimer.interpolate_property(secondaryHitArea, "translation:x", 0, secondaryAttackDist, secondaryAttackDuration, Tween.TRANS_LINEAR, Tween.EASE_IN) + attackTimer.interpolate_property(hitArea, "translation:x", distance, 0, wait-duration, Tween.TRANS_LINEAR, Tween.EASE_OUT) attackTimer.start() # Once the movement is finished, turn off the hitbox and visual feedback yield(attackTimer, "tween_completed") - secondaryHitArea.set_monitoring(false) - secondaryHitArea.set_visible(false) isAttacking = false + hitArea.set_monitoring(false) + hitArea.set_visible(false) # Called when detected by an attack's hitbox @@ -326,17 +351,17 @@ func _on_generalHitArea_entered(damageVar:int, directionVar:Vector3, strengthVar # Rotate the vector depending on the player orientation direction.x*=bodyRotation - print("body named " + body.name + " hit: primary") + print("body named " + body.name + " hit: punch") # 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) +# punch hit has landed on something +func _on_punchHitArea_body_entered(body:Node): + _on_generalHitArea_entered(punchAttackDmg, punchAttackDirection, punchAttackStrength, body) -# Secondary hit has landed on something -func _on_secondaryHitArea_body_entered(body:Node): - _on_generalHitArea_entered(secondaryAttackDmg, secondaryAttackDirection, secondaryAttackStrength, body) +# kick hit has landed on something +func _on_kickHitArea_body_entered(body:Node): + _on_generalHitArea_entered(kickAttackDmg, kickAttackDirection, kickAttackStrength, body) diff --git a/server/entities/characters/player.tscn b/server/entities/characters/player.tscn index 2446447..dc28c08 100644 --- a/server/entities/characters/player.tscn +++ b/server/entities/characters/player.tscn @@ -31,38 +31,39 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.17856, 0 ) radius = 0.2 radial_segments = 24 -[node name="primaryHitArea" type="Area" parent="."] +[node name="punchHitArea" type="Area" parent="."] visible = false monitoring = false collision_layer = 0 collision_mask = 2 -[node name="primaryHitCol" type="CollisionShape" parent="primaryHitArea"] +[node name="punchHitCol" type="CollisionShape" parent="punchHitArea"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.420072, 0.815, 0 ) shape = SubResource( 2 ) -[node name="primaryHitCSG" type="CSGBox" parent="primaryHitArea"] +[node name="punchHitCSG" type="CSGBox" parent="punchHitArea"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.419673, 0.815, 0 ) width = 1.09437 height = 0.400067 depth = 0.618424 -[node name="secondaryHitArea" type="Area" parent="."] +[node name="kickHitArea" type="Area" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.378735, 0 ) visible = false monitoring = false collision_layer = 0 collision_mask = 2 -[node name="secondaryHitCol" type="CollisionShape" parent="secondaryHitArea"] +[node name="kickHitCol" type="CollisionShape" parent="kickHitArea"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.42, 0.2, 0 ) shape = SubResource( 2 ) -[node name="secondaryHitCSG" type="CSGBox" parent="secondaryHitArea"] +[node name="kickHitCSG" type="CSGBox" parent="kickHitArea"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.42, 0.2, 0 ) width = 1.09437 height = 0.400067 depth = 0.618424 [node name="attackTween" type="Tween" parent="."] -[connection signal="body_entered" from="primaryHitArea" to="." method="_on_primaryHitArea_body_entered"] -[connection signal="body_entered" from="secondaryHitArea" to="." method="_on_secondaryHitArea_body_entered"] +[connection signal="body_entered" from="punchHitArea" to="." method="_on_punchHitArea_body_entered"] +[connection signal="body_entered" from="kickHitArea" to="." method="_on_kickHitArea_body_entered"] -- GitLab