From e56d80972929d95f4e67309b9a122776d1aefd02 Mon Sep 17 00:00:00 2001 From: Canopteks <thomas.duhamel@protonmail.com> Date: Thu, 5 Mar 2020 08:29:18 +0100 Subject: [PATCH] basic throws, need to fix momentum --- client/levels/test/game.gd | 3 ++- server/entities/characters/player.gd | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client/levels/test/game.gd b/client/levels/test/game.gd index 08680e3..22df655 100644 --- a/client/levels/test/game.gd +++ b/client/levels/test/game.gd @@ -44,7 +44,8 @@ func getPlayerInput(): # Sent without safety resend rpc_unreliable_id(1, "sendPlayerInputs", movementInput, jumpInput, jumpId, sprintInput, attackStateInput) - + + puppet func backToLobby(): #get_node("/root/lobby").show() get_tree().quit() diff --git a/server/entities/characters/player.gd b/server/entities/characters/player.gd index a87dfd2..e514a60 100644 --- a/server/entities/characters/player.gd +++ b/server/entities/characters/player.gd @@ -5,6 +5,7 @@ onready var ownId:int = int(self.name) ######## MOVEMENT AND POSITION VARS ######## onready var collisionShape:CollisionShape = $collisionShape +var bodyRotation:int = 1 # Speed values const MAX_SPEED:float = 8.0 @@ -95,8 +96,10 @@ func getPlayerInputs(movementInput, jumpInput, jumpId, sprintInput, attackTypeIn func processMovement(delta): # Set the side faced by the character if motion > 0: + bodyRotation = 1 set_rotation_degrees(Vector3(0, 0, 0)) elif motion < 0: + bodyRotation = -1 set_rotation_degrees(Vector3(0, 180, 0)) if self.is_on_floor(): @@ -142,6 +145,11 @@ func processMovement(delta): # Update the velocity after the collisions (physical engine ftw) vel = self.move_and_slide(vel, FLOOR_NORMAL) + +# if get_slide_count() > 0: +# var collision = get_slide_collision(0) +# if collision != null: +# vel = vel.bounce(collision.normal) # Send the position of the player @@ -195,8 +203,9 @@ func secondaryAttack(): # Called when detected by an attack's hitbox -func hurt(damages:int, sourceId:int): +func hurt(damages:int, sourceId:int, force:Vector3): hp += damages + vel += Vector3(force.x*hp,force.y,force.z) lastStrikerId = sourceId rpc_unreliable_id(ownId, "hurt", hp) @@ -209,17 +218,19 @@ func die(): # Primary hit has landed on something func _on_primaryHitArea_body_entered(body): + var force = Vector3(bodyRotation, 8, 0) if int(body.name)==ownId: return print("body named " + body.name + " hit: primary") - body.hurt(primaryAttackDmg, ownId) + body.hurt(primaryAttackDmg, ownId, force) # Secondary hit has landed on something func _on_secondaryHitArea_body_entered(body): + var force = Vector3(bodyRotation, 0, 0) if int(body.name)==ownId: return print("body named " + body.name + " hit: secondary") - body.hurt(secondaryAttackDmg, ownId) + body.hurt(secondaryAttackDmg, ownId, force) -- GitLab