Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @export var total_air_actions := 2
- @export var current_air_actions := 1
- @export var jump_height : float = 6.0
- @export var jump_time_to_peak : float = 0.5
- @export var jump_time_to_descent : float = 0.4
- #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.
- @onready var jump_velocity : float = (2.0 * jump_height) / jump_time_to_peak
- @onready var jump_gravity : float = (-2.0 * jump_height) / (jump_time_to_peak * jump_time_to_peak)
- @onready var fall_gravity : float = (-2.0 * jump_height) / (jump_time_to_descent * jump_time_to_descent)
- func _physics_process(delta: float) -> void:
- #gravity
- velocity.y += get_personal_gravity() * delta
- #jumping
- jump_logic(delta)
- func get_personal_gravity() -> float:
- return jump_gravity if velocity.y > 0.0 else fall_gravity
- func jump_logic(delta) -> void:
- # falling
- if not is_on_floor():
- velocity += (get_gravity() * 4.0) * delta
- else:
- current_air_actions = total_air_actions
- # jumping
- if Input.is_action_just_pressed("FaceDown") and current_air_actions > 0:
- velocity.y = jump_velocity
- current_air_actions -= 1
- # jump shortening if you release the button before you're at max height
- if Input.is_action_just_released("FaceDown") and velocity.y >= 0:
- velocity.y *= 0.6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement