Add basic jump

This commit is contained in:
Jarrod Doyle 2024-02-23 11:21:40 +00:00
parent a20c1fcbfb
commit 4efbfe667e
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 12 additions and 1 deletions

View File

@ -55,6 +55,8 @@ extends PhysicsBody3D
## accurate. 4 is a decent number for low poly terrain! ## accurate. 4 is a decent number for low poly terrain!
@export var max_iteration_count := 4 @export var max_iteration_count := 4
var jump_speed := 4.5
var jump_pressed := false
var gravity := 9.8 var gravity := 9.8
var max_speed := 8 var max_speed := 8
@ -108,6 +110,8 @@ func get_input() -> Vector2:
elif !Input.is_key_pressed(KEY_ESCAPE): elif !Input.is_key_pressed(KEY_ESCAPE):
escape_pressed = 0 escape_pressed = 0
jump_pressed = Input.is_action_just_pressed("cc_jump")
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED: if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
return Vector2(0,0) return Vector2(0,0)
@ -129,7 +133,6 @@ func get_input() -> Vector2:
return input_dir.rotated(-body.rotation.y) return input_dir.rotated(-body.rotation.y)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
# Before Move # Before Move
var _desired_horz_velocity := get_input() var _desired_horz_velocity := get_input()
var desired_horz_velocity := Vector3.ZERO var desired_horz_velocity := Vector3.ZERO
@ -145,6 +148,8 @@ func _physics_process(delta: float) -> void:
if !grounded: if !grounded:
desired_vertical_velocity.y = _velocity.y desired_vertical_velocity.y = _velocity.y
elif jump_pressed:
desired_vertical_velocity.y = jump_speed
desired_vertical_velocity.y -= gravity * delta desired_vertical_velocity.y -= gravity * delta

View File

@ -60,6 +60,12 @@ cc_right={
cc_sprint={ cc_sprint={
"deadzone": 0.5, "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) "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) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
] ]
} }