feat: included a duck jump
This commit is contained in:
parent
80c69b5e2b
commit
fab18d3a98
@ -26,9 +26,11 @@ var max_velocity := {
|
|||||||
"fall": Vector2(120, 420),
|
"fall": Vector2(120, 420),
|
||||||
"walljump": 200,
|
"walljump": 200,
|
||||||
"idle": 12000,
|
"idle": 12000,
|
||||||
"duck": 160,
|
"duck": 165,
|
||||||
"duck_walk": 160
|
"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
|
var velocity_jump_boost_ratio := 10
|
||||||
# This is added to the acceleration force initially
|
# This is added to the acceleration force initially
|
||||||
var init_acceleration_force := {"": 0, "idle_walk": 4181, "idle_run": 5765, "walk_run": 1000}
|
var init_acceleration_force := {"": 0, "idle_walk": 4181, "idle_run": 5765, "walk_run": 1000}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ onready var init_boost_type = player_state_machine.init_boost_type
|
|||||||
|
|
||||||
var wall_touch_direction = 1
|
var wall_touch_direction = 1
|
||||||
var stomping = false
|
var stomping = false
|
||||||
|
var duck_jumping = false
|
||||||
var floor_angle = Vector2(0, 0)
|
var floor_angle = Vector2(0, 0)
|
||||||
var previous_rotation = 0
|
var previous_rotation = 0
|
||||||
var snap_possible = true
|
var snap_possible = true
|
||||||
@ -251,10 +252,17 @@ func calculate_jump_velocity(linear_velocity: Vector2, delta: float, direction:
|
|||||||
if stomping:
|
if stomping:
|
||||||
additive_jump_force += calculate_stomp_velocity(delta)
|
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":
|
if state != "jump":
|
||||||
linear_velocity.y = PhysicsFunc.two_step_euler(
|
linear_velocity.y = PhysicsFunc.two_step_euler(
|
||||||
linear_velocity.y,
|
linear_velocity.y,
|
||||||
(acceleration_force[state].y / delta + additive_jump_force) * -1,
|
(y_acceleration_force / delta + additive_jump_force) * -1,
|
||||||
mass,
|
mass,
|
||||||
delta
|
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)
|
var movement_factor = absolut + abs(velocity.x) / (max_velocity["fall"].x * divisor)
|
||||||
linear_velocity.x = PhysicsFunc.two_step_euler(
|
linear_velocity.x = PhysicsFunc.two_step_euler(
|
||||||
linear_velocity.x,
|
linear_velocity.x,
|
||||||
acceleration_force[state].x * movement_factor * direction.x,
|
x_acceleration_force * movement_factor * direction.x,
|
||||||
mass,
|
mass,
|
||||||
delta
|
delta
|
||||||
)
|
)
|
||||||
|
|||||||
@ -217,6 +217,12 @@ func _enter_state(new_state, old_state):
|
|||||||
|
|
||||||
if new_state == "run":
|
if new_state == "run":
|
||||||
running_particles.emitting = true
|
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":
|
if new_state == "jump":
|
||||||
jump_point_particles.position.x = 0 if facing == 1 else 24
|
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()
|
jump_point_particles.restart()
|
||||||
|
|
||||||
if !["run", "walk", "idle", "duck"].has(old_state) && parent.is_on_floor():
|
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")
|
emit_signal("got_grounded")
|
||||||
|
|
||||||
match new_state:
|
match new_state:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user