From 50efc5d5d59f933950aced1fa838380616bbeb37 Mon Sep 17 00:00:00 2001 From: Lamoot Date: Wed, 13 Dec 2023 20:50:35 +0100 Subject: [PATCH 1/4] Multi-jump system, as many umps as desired. Instead of hard-coding the jumping mechanic to solely 2 jumps, i.e. double-jump, allow for any number of jumps. By default this is still set to 2, but more are possible if required. --- objects/player.gd | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/objects/player.gd b/objects/player.gd index 7923aae..b40c301 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -2,6 +2,7 @@ extends CharacterBody3D @export_subgroup("Properties") @export var movement_speed = 5 +@export_range(0, 100) var number_of_jumps:int = 2 @export var jump_strength = 8 @export_subgroup("Weapons") @@ -25,8 +26,7 @@ var gravity := 0.0 var previously_floored := false -var jump_single := true -var jump_double := true +var jumps_remaining:int var container_offset = Vector3(1.2, -1.1, -2.75) @@ -148,15 +148,8 @@ func handle_controls(_delta): if Input.is_action_just_pressed("jump"): - if jump_single or jump_double: - Audio.play("sounds/jump_a.ogg, sounds/jump_b.ogg, sounds/jump_c.ogg") - - if jump_double: - - gravity = -jump_strength - jump_double = false - - if(jump_single): action_jump() + if jumps_remaining: + action_jump() # Weapon switching @@ -170,17 +163,15 @@ func handle_gravity(delta): if gravity > 0 and is_on_floor(): - jump_single = true + jumps_remaining = number_of_jumps gravity = 0 # Jumping -func action_jump(): - - gravity = -jump_strength - - jump_single = false; - jump_double = true; +func action_jump(): + Audio.play("sounds/jump_a.ogg, sounds/jump_b.ogg, sounds/jump_c.ogg") + gravity = -jump_strength + jumps_remaining -= 1 # Shooting From 9efe92d92ee3dbbcbea4e950580c9fccb2857921 Mon Sep 17 00:00:00 2001 From: Kurt Burgoyne Date: Sat, 13 Jan 2024 11:18:52 +0000 Subject: [PATCH 2/4] Seperated Controller and Mouse camera rotation. --- objects/player.gd | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/objects/player.gd b/objects/player.gd index 7923aae..d68bb9a 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -60,7 +60,7 @@ func _physics_process(delta): handle_gravity(delta) # Movement - + var applied_velocity: Vector3 movement_velocity = transform.basis * movement_velocity # Move forward @@ -71,13 +71,8 @@ func _physics_process(delta): velocity = applied_velocity move_and_slide() - # Rotation - - camera.rotation.z = lerp_angle(camera.rotation.z, -input_mouse.x * 25 * delta, delta * 5) - - camera.rotation.x = lerp_angle(camera.rotation.x, rotation_target.x, delta * 25) - rotation.y = lerp_angle(rotation.y, rotation_target.y, delta * 25) - + # Rotation + #camera.rotation.z = lerp_angle(camera.rotation.z, -input_mouse.x * 25 * delta, delta * 5) container.position = lerp(container.position, container_offset - (basis.inverse() * applied_velocity / 30), delta * 10) # Movement sound @@ -107,13 +102,10 @@ func _physics_process(delta): func _input(event): if event is InputEventMouseMotion and mouse_captured: - input_mouse = event.relative / mouse_sensitivity - - rotation_target.y -= event.relative.x / mouse_sensitivity - rotation_target.x -= event.relative.y / mouse_sensitivity + handle_rotation(event.relative.x, event.relative.y, false) -func handle_controls(_delta): +func handle_controls(delta): # Mouse capture @@ -128,17 +120,13 @@ func handle_controls(_delta): input_mouse = Vector2.ZERO # Movement - var input := Input.get_vector("move_left", "move_right", "move_forward", "move_back") - movement_velocity = Vector3(input.x, 0, input.y).normalized() * movement_speed - # Rotation - + # Handle Controller Rotation var rotation_input := Input.get_vector("camera_right", "camera_left", "camera_down", "camera_up") - - rotation_target -= Vector3(-rotation_input.y, -rotation_input.x, 0).limit_length(1.0) * gamepad_sensitivity - rotation_target.x = clamp(rotation_target.x, deg_to_rad(-90), deg_to_rad(90)) + if rotation_input: + handle_rotation(rotation_input.x, rotation_input.y, true, delta) # Shooting @@ -162,10 +150,23 @@ func handle_controls(_delta): action_weapon_toggle() +# Camera rotation + +func handle_rotation(xRot: float, yRot: float, isController: bool, delta: float = 0.0): + if isController: + rotation_target -= Vector3(-yRot, -xRot, 0).limit_length(1.0) * gamepad_sensitivity + rotation_target.x = clamp(rotation_target.x, deg_to_rad(-90), deg_to_rad(90)) + camera.rotation.x = lerp_angle(camera.rotation.x, rotation_target.x, delta * 25) + rotation.y = lerp_angle(rotation.y, rotation_target.y, delta * 25) + else: + rotation_target += (Vector3(-yRot, -xRot, 0) / mouse_sensitivity) + rotation_target.x = clamp(rotation_target.x, deg_to_rad(-90), deg_to_rad(90)) + camera.rotation.x = rotation_target.x; + rotation.y = rotation_target.y; + # Handle gravity func handle_gravity(delta): - gravity += 20 * delta if gravity > 0 and is_on_floor(): From 45036ffa9c9bb72e85da14d57ff25ef307a80107 Mon Sep 17 00:00:00 2001 From: Kurt Burgoyne Date: Sat, 13 Jan 2024 11:20:35 +0000 Subject: [PATCH 3/4] Removed left over comment --- objects/player.gd | 1 - 1 file changed, 1 deletion(-) diff --git a/objects/player.gd b/objects/player.gd index d68bb9a..c6a5aba 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -72,7 +72,6 @@ func _physics_process(delta): move_and_slide() # Rotation - #camera.rotation.z = lerp_angle(camera.rotation.z, -input_mouse.x * 25 * delta, delta * 5) container.position = lerp(container.position, container_offset - (basis.inverse() * applied_velocity / 30), delta * 10) # Movement sound From e48c8260678331fe1150c41363c8282ba7a990cd Mon Sep 17 00:00:00 2001 From: V <61495413+kelo221@users.noreply.github.com> Date: Wed, 10 Apr 2024 19:07:35 +0300 Subject: [PATCH 4/4] Fix shot accuracy The camera gets moved upward before the gun fires, this causes the impact scene and the target of the shot to be incorrect. --- objects/player.gd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/objects/player.gd b/objects/player.gd index 7923aae..da785d2 100644 --- a/objects/player.gd +++ b/objects/player.gd @@ -192,10 +192,6 @@ func action_shoot(): Audio.play(weapon.sound_shoot) - container.position.z += 0.25 # Knockback of weapon visual - camera.rotation.x += 0.025 # Knockback of camera - movement_velocity += Vector3(0, 0, weapon.knockback) # Knockback - # Set muzzle flash position, play animation muzzle.play("default") @@ -234,7 +230,11 @@ func action_shoot(): get_tree().root.add_child(impact_instance) impact_instance.position = raycast.get_collision_point() + (raycast.get_collision_normal() / 10) - impact_instance.look_at(camera.global_transform.origin, Vector3.UP, true) + impact_instance.look_at(camera.global_transform.origin, Vector3.UP, true) + + container.position.z += 0.25 # Knockback of weapon visual + camera.rotation.x += 0.025 # Knockback of camera + movement_velocity += Vector3(0, 0, weapon.knockback) # Knockback # Toggle between available weapons (listed in 'weapons')