Melhoria de codigo do game

This commit is contained in:
2026-05-04 13:08:38 -03:00
parent d01e2e8578
commit c95f8f98d8
3 changed files with 45 additions and 3 deletions
+17 -1
View File
@@ -7,8 +7,11 @@ const JUMP_VELOCITY = 10.0
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var view : Node3D
@export var timer : Timer
var movement_velocity : Vector3
var rotation_direction : float
var can_jump := true
var can_timeout := true
func _physics_process(delta: float) -> void:
handle_input(delta)
@@ -16,6 +19,13 @@ func _physics_process(delta: float) -> void:
jump()
handle_animations()
if is_on_floor():
can_jump = true
else:
if can_timeout:
timer.start()
can_timeout = false
var applied_velocity : Vector3
applied_velocity = velocity.lerp(movement_velocity, delta * 10)
applied_velocity.y = -gravity
@@ -55,8 +65,14 @@ func apply_gravity(delta):
gravity += 25 * delta
func jump():
if Input.is_action_just_pressed("move_jump") and is_on_floor():
if Input.is_action_just_pressed("move_jump") and can_jump:
gravity = -JUMP_VELOCITY
can_jump = false
if gravity > 0 and is_on_floor():
gravity = 0
func _on_timer_timeout() -> void:
can_jump = false
can_timeout = true