From 4efbfe667ecc7e201e5b4ba6b425ac10074257d2 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 23 Feb 2024 11:21:40 +0000 Subject: [PATCH] Add basic jump --- content/scripts/player.gd | 7 ++++++- project.godot | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 46fee0b..3757065 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -55,6 +55,8 @@ extends PhysicsBody3D ## accurate. 4 is a decent number for low poly terrain! @export var max_iteration_count := 4 +var jump_speed := 4.5 +var jump_pressed := false var gravity := 9.8 var max_speed := 8 @@ -107,6 +109,8 @@ func get_input() -> Vector2: escape_pressed = 1 elif !Input.is_key_pressed(KEY_ESCAPE): escape_pressed = 0 + + jump_pressed = Input.is_action_just_pressed("cc_jump") if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED: return Vector2(0,0) @@ -129,7 +133,6 @@ func get_input() -> Vector2: return input_dir.rotated(-body.rotation.y) func _physics_process(delta: float) -> void: - # Before Move var _desired_horz_velocity := get_input() var desired_horz_velocity := Vector3.ZERO @@ -145,6 +148,8 @@ func _physics_process(delta: float) -> void: if !grounded: desired_vertical_velocity.y = _velocity.y + elif jump_pressed: + desired_vertical_velocity.y = jump_speed desired_vertical_velocity.y -= gravity * delta diff --git a/project.godot b/project.godot index 226c822..7830548 100644 --- a/project.godot +++ b/project.godot @@ -60,6 +60,12 @@ cc_right={ cc_sprint={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) +] +} +cc_jump={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] }