feat: included a duck jump

This commit is contained in:
Jakob Feldmann 2023-09-18 15:47:31 +02:00
parent 80c69b5e2b
commit fab18d3a98
3 changed files with 22 additions and 4 deletions

View File

@ -26,9 +26,11 @@ var max_velocity := {
"fall": Vector2(120, 420),
"walljump": 200,
"idle": 12000,
"duck": 160,
"duck_walk": 160
"duck": 165,
"duck_walk": 165
}
# x is applied directly to velocity and y is multiplied with acceleration
var duck_boost = Vector2(2.5, 0.75)
var velocity_jump_boost_ratio := 10
# This is added to the acceleration force initially
var init_acceleration_force := {"": 0, "idle_walk": 4181, "idle_run": 5765, "walk_run": 1000}

View File

@ -20,6 +20,7 @@ onready var init_boost_type = player_state_machine.init_boost_type
var wall_touch_direction = 1
var stomping = false
var duck_jumping = false
var floor_angle = Vector2(0, 0)
var previous_rotation = 0
var snap_possible = true
@ -251,10 +252,17 @@ func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction:
if stomping:
additive_jump_force += calculate_stomp_velocity(delta)
var y_acceleration_force = acceleration_force[state].y
var x_acceleration_force = acceleration_force[state].x
if duck_jumping:
y_acceleration_force *= duck_boost.y
linear_velocity.x += duck_boost.x * direction.x
if state != "jump":
linear_velocity.y = PhysicsFunc.two_step_euler(
linear_velocity.y,
(acceleration_force[state].y / delta + additive_jump_force) * -1,
(y_acceleration_force / delta + additive_jump_force) * -1,
mass,
delta
)
@ -281,7 +289,7 @@ func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction:
var movement_factor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor)
linear_velocity.x = PhysicsFunc.two_step_euler(
linear_velocity.x,
acceleration_force[state].x * movement_factor * direction.x,
x_acceleration_force * movement_factor * direction.x,
mass,
delta
)

View File

@ -217,6 +217,12 @@ func _enter_state(new_state, old_state):
if new_state == "run":
running_particles.emitting = true
if new_state == "duck" || new_state == "duck_walk":
parent.duck_jumping = true
if new_state == "wallslide":
parent.duck_jumping = false
if new_state == "jump":
jump_point_particles.position.x = 0 if facing == 1 else 24
@ -224,6 +230,8 @@ func _enter_state(new_state, old_state):
jump_point_particles.restart()
if !["run", "walk", "idle", "duck"].has(old_state) && parent.is_on_floor():
if(new_state != "duck" && new_state != "duck_walk"):
parent.duck_jumping = false
emit_signal("got_grounded")
match new_state: