Advertisement
Guest User

jump stuff so far

a guest
Jun 11th, 2025
36
0
5 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. @export var total_air_actions := 2
  2. @export var current_air_actions := 1
  3. @export var jump_height : float = 6.0
  4. @export var jump_time_to_peak : float = 0.5
  5. @export var jump_time_to_descent : float = 0.4
  6. #im gonna be real i dont know how this math works i just picked it up off the guide. apparently it's a bunch of projectile calculations via algebra, which while cool is something i gotta pick apart to really learn.
  7. @onready var jump_velocity : float = (2.0 * jump_height) / jump_time_to_peak
  8. @onready var jump_gravity : float = (-2.0 * jump_height) / (jump_time_to_peak * jump_time_to_peak)
  9. @onready var fall_gravity : float = (-2.0 * jump_height) / (jump_time_to_descent * jump_time_to_descent)
  10.  
  11.  
  12. func _physics_process(delta: float) -> void:
  13. #gravity
  14. velocity.y += get_personal_gravity() * delta
  15. #jumping
  16. jump_logic(delta)
  17.  
  18.  
  19. func get_personal_gravity() -> float:
  20. return jump_gravity if velocity.y > 0.0 else fall_gravity
  21.  
  22. func jump_logic(delta) -> void:
  23. # falling
  24. if not is_on_floor():
  25. velocity += (get_gravity() * 4.0) * delta
  26. else:
  27. current_air_actions = total_air_actions
  28. # jumping
  29. if Input.is_action_just_pressed("FaceDown") and current_air_actions > 0:
  30. velocity.y = jump_velocity
  31. current_air_actions -= 1
  32. # jump shortening if you release the button before you're at max height
  33. if Input.is_action_just_released("FaceDown") and velocity.y >= 0:
  34. velocity.y *= 0.6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement