Acceleration independent of physics fps, tile fix
The tiles had not perfectly quadratic shapes, so they caused some bugs. I also made a adjustment to the reverse movement check and the recovery of the strafe move when touching walls.
This commit is contained in:
parent
f75c76e437
commit
f79e483a57
@ -66,6 +66,7 @@ enabled=PoolStringArray( "res://addons/AsepriteWizard/plugin.cfg" )
|
|||||||
[global]
|
[global]
|
||||||
|
|
||||||
window=false
|
window=false
|
||||||
|
grav=false
|
||||||
|
|
||||||
[importer_defaults]
|
[importer_defaults]
|
||||||
|
|
||||||
|
|||||||
@ -8,10 +8,6 @@ onready var player_state_machine = $BlobbyStateMachine
|
|||||||
onready var init_boost = player_state_machine.init_boost
|
onready var init_boost = player_state_machine.init_boost
|
||||||
onready var init_boost_type = player_state_machine.init_boost_type
|
onready var init_boost_type = player_state_machine.init_boost_type
|
||||||
onready var animation_player = $BlobbySprite/BlobbymationPlayer
|
onready var animation_player = $BlobbySprite/BlobbymationPlayer
|
||||||
# TODO Too much speed through midair boosting
|
|
||||||
# TODO Jumping near walls is buggy
|
|
||||||
# TODO Falling and then touching walls is too fast
|
|
||||||
# TODO Couple one time applications of force to delta to keep values constant for different physics fps
|
|
||||||
|
|
||||||
|
|
||||||
# When the Enemy stomp AREA enters the enemy collision area -> stomp
|
# When the Enemy stomp AREA enters the enemy collision area -> stomp
|
||||||
@ -61,6 +57,7 @@ func calculate_grounded_velocity(
|
|||||||
|
|
||||||
# Slowing down movement when not controlling direction
|
# Slowing down movement when not controlling direction
|
||||||
if is_equal_approx(direction.x, 0):
|
if is_equal_approx(direction.x, 0):
|
||||||
|
# TODO Handle Deadzones
|
||||||
out_vel.x = PhysicsFunc.two_step_euler(
|
out_vel.x = PhysicsFunc.two_step_euler(
|
||||||
out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta
|
out_vel.x, deceleration_force * -1 * velocity_direction, mass, delta
|
||||||
)
|
)
|
||||||
@ -71,6 +68,7 @@ func calculate_grounded_velocity(
|
|||||||
# When turning the opposite direction, friction is added to the opposite acceleration movement
|
# When turning the opposite direction, friction is added to the opposite acceleration movement
|
||||||
var reverse_move = is_reversing_horizontal_movement(direction)
|
var reverse_move = is_reversing_horizontal_movement(direction)
|
||||||
if reverse_move:
|
if reverse_move:
|
||||||
|
# TODO dont put constants in here
|
||||||
out_vel.x = PhysicsFunc.two_step_euler(
|
out_vel.x = PhysicsFunc.two_step_euler(
|
||||||
out_vel.x,
|
out_vel.x,
|
||||||
deceleration_force * -3.42 * velocity_direction,
|
deceleration_force * -3.42 * velocity_direction,
|
||||||
@ -117,7 +115,7 @@ func calculate_grounded_velocity(
|
|||||||
func is_reversing_horizontal_movement(direction: Vector2) -> bool:
|
func is_reversing_horizontal_movement(direction: Vector2) -> bool:
|
||||||
return (
|
return (
|
||||||
(direction.x > 0 && velocity.x < 0)
|
(direction.x > 0 && velocity.x < 0)
|
||||||
|| (direction.x < 0 && velocity.x >= 0)
|
|| (direction.x < 0 && velocity.x > 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -150,8 +148,7 @@ func is_correct_airstrafe_input() -> bool:
|
|||||||
air_strafe_charges > 0
|
air_strafe_charges > 0
|
||||||
&& (
|
&& (
|
||||||
Input.is_action_just_pressed("move_right")
|
Input.is_action_just_pressed("move_right")
|
||||||
||
|
|| Input.is_action_just_pressed("move_left")
|
||||||
Input.is_action_just_pressed("move_left")
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,16 +162,12 @@ func calculate_jump_velocity(
|
|||||||
linear_velocity: Vector2, delta: float, direction: Vector2
|
linear_velocity: Vector2, delta: float, direction: Vector2
|
||||||
) -> Vector2:
|
) -> Vector2:
|
||||||
var state = player_state_machine.state
|
var state = player_state_machine.state
|
||||||
var walljumping = is_correct_walljump_input(direction)
|
|
||||||
var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass
|
var additive_jump_force = velocity_jump_boost_ratio * abs(velocity.x) * mass
|
||||||
|
|
||||||
if state != "jump":
|
if state != "jump":
|
||||||
if state == "idle":
|
|
||||||
additive_jump_force = 0
|
|
||||||
|
|
||||||
linear_velocity.y = PhysicsFunc.two_step_euler(
|
linear_velocity.y = PhysicsFunc.two_step_euler(
|
||||||
linear_velocity.y,
|
linear_velocity.y,
|
||||||
(acceleration_force[state].y + additive_jump_force) * -1,
|
(acceleration_force[state].y / delta + additive_jump_force) * -1,
|
||||||
mass,
|
mass,
|
||||||
delta
|
delta
|
||||||
)
|
)
|
||||||
@ -182,8 +175,8 @@ func calculate_jump_velocity(
|
|||||||
if !Input.is_action_pressed("jump"):
|
if !Input.is_action_pressed("jump"):
|
||||||
# TODO This is so good not gonna lie
|
# TODO This is so good not gonna lie
|
||||||
# Smooth transition from jumping to falling
|
# Smooth transition from jumping to falling
|
||||||
if velocity.y > _gravity * delta * 20:
|
if velocity.y > _gravity * delta * 10:
|
||||||
linear_velocity.y += _gravity * delta * 20
|
linear_velocity.y += _gravity * delta * 10
|
||||||
else:
|
else:
|
||||||
linear_velocity.y += (
|
linear_velocity.y += (
|
||||||
max(abs(linear_velocity.y), _gravity * delta)
|
max(abs(linear_velocity.y), _gravity * delta)
|
||||||
@ -193,21 +186,12 @@ func calculate_jump_velocity(
|
|||||||
else:
|
else:
|
||||||
linear_velocity.y += _gravity * delta
|
linear_velocity.y += _gravity * delta
|
||||||
|
|
||||||
# TODO Dis shizzle buggy
|
# TODO This poop too
|
||||||
if (-4 < velocity.x and velocity.x < 4) :
|
if -4 < velocity.x and velocity.x < 4:
|
||||||
linear_velocity.x += inair_velocity * direction.x
|
linear_velocity.x += inair_velocity * direction.x
|
||||||
|
|
||||||
if is_correct_airstrafe_input() && !walljumping:
|
if is_correct_airstrafe_input():
|
||||||
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
|
linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
|
||||||
linear_velocity.x = PhysicsFunc.two_step_euler(
|
|
||||||
linear_velocity.x,
|
|
||||||
acceleration_force["air_strafe"].x * direction.x,
|
|
||||||
mass,
|
|
||||||
delta
|
|
||||||
)
|
|
||||||
air_strafe_charges -= 1
|
|
||||||
# TODO Suspend in air
|
|
||||||
|
|
||||||
return linear_velocity
|
return linear_velocity
|
||||||
|
|
||||||
|
|
||||||
@ -223,20 +207,13 @@ func calculate_fall_velocity(
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
linear_velocity.y = max_velocity["fall"]
|
linear_velocity.y = max_velocity["fall"]
|
||||||
if (-4 < velocity.x and velocity.x < 4) :
|
if -4 < velocity.x and velocity.x < 4:
|
||||||
# TODO This is poop
|
# TODO This is poop
|
||||||
linear_velocity.x += inair_velocity * direction.x
|
linear_velocity.x += inair_velocity * direction.x
|
||||||
if Input.is_action_just_pressed("jump"):
|
if Input.is_action_just_pressed("jump"):
|
||||||
jump_buffer_filled = true
|
jump_buffer_filled = true
|
||||||
if is_correct_airstrafe_input():
|
if is_correct_airstrafe_input():
|
||||||
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
|
linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
|
||||||
linear_velocity.x = PhysicsFunc.two_step_euler(
|
|
||||||
linear_velocity.x,
|
|
||||||
acceleration_force["air_strafe"].x * direction.x,
|
|
||||||
mass,
|
|
||||||
delta
|
|
||||||
)
|
|
||||||
air_strafe_charges -= 1
|
|
||||||
return linear_velocity
|
return linear_velocity
|
||||||
|
|
||||||
|
|
||||||
@ -246,28 +223,45 @@ func calculate_wallslide_velocity(
|
|||||||
# Walljump mechanics
|
# Walljump mechanics
|
||||||
if is_correct_walljump_input(direction):
|
if is_correct_walljump_input(direction):
|
||||||
linear_velocity.x = PhysicsFunc.two_step_euler(
|
linear_velocity.x = PhysicsFunc.two_step_euler(
|
||||||
0, acceleration_force["walljump"].x * direction.x, mass, delta
|
0,
|
||||||
)
|
acceleration_force["walljump"].x / delta * direction.x,
|
||||||
linear_velocity.y = PhysicsFunc.two_step_euler(
|
|
||||||
0, acceleration_force["walljump"].y * -1, mass, delta
|
|
||||||
)
|
|
||||||
# TODO this is done 3 times for different states
|
|
||||||
# TODO make air strafe a portionable boost instead of a one time acceleration (or not?! whaaat?)
|
|
||||||
elif is_correct_airstrafe_input():
|
|
||||||
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
|
|
||||||
linear_velocity.x = PhysicsFunc.two_step_euler(
|
|
||||||
linear_velocity.x,
|
|
||||||
acceleration_force["air_strafe"].x * velocity.x,
|
|
||||||
mass,
|
mass,
|
||||||
delta
|
delta
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
linear_velocity.y = PhysicsFunc.two_step_euler(
|
linear_velocity.y = PhysicsFunc.two_step_euler(
|
||||||
linear_velocity.y, _gravity * mass * 0.5, mass, delta
|
0, acceleration_force["walljump"].y / delta * -1, mass, delta
|
||||||
)
|
)
|
||||||
|
elif is_correct_airstrafe_input():
|
||||||
|
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
|
||||||
|
linear_velocity = execute_airstrafe(linear_velocity, delta, direction)
|
||||||
|
else:
|
||||||
|
# TODO dont put constants in here
|
||||||
|
linear_velocity.y = PhysicsFunc.two_step_euler(
|
||||||
|
linear_velocity.y*0.88, _gravity * mass, mass, delta
|
||||||
|
)
|
||||||
|
air_strafe_charges = 1
|
||||||
return linear_velocity
|
return linear_velocity
|
||||||
|
|
||||||
|
|
||||||
|
func execute_airstrafe(
|
||||||
|
linear_velocity: Vector2, delta: float, direction: Vector2
|
||||||
|
) -> Vector2:
|
||||||
|
# var rev = 1 if !is_reversing_horizontal_movement(direction) else -1
|
||||||
|
if is_reversing_horizontal_movement(direction):
|
||||||
|
linear_velocity.x = 0
|
||||||
|
linear_velocity.x = PhysicsFunc.two_step_euler(
|
||||||
|
linear_velocity.x,
|
||||||
|
acceleration_force["air_strafe"].x / delta * direction.x,
|
||||||
|
mass,
|
||||||
|
delta
|
||||||
|
)
|
||||||
|
if linear_velocity.y > 0:
|
||||||
|
linear_velocity.y = 0
|
||||||
|
air_strafe_charges -= 1
|
||||||
|
return linear_velocity
|
||||||
|
# TODO Suspend in air
|
||||||
|
|
||||||
|
|
||||||
func calculate_stomp_velocity(
|
func calculate_stomp_velocity(
|
||||||
linear_velocity: Vector2, impulse: float
|
linear_velocity: Vector2, impulse: float
|
||||||
) -> Vector2:
|
) -> Vector2:
|
||||||
|
|||||||
@ -114,7 +114,7 @@ func _get_transition(_delta):
|
|||||||
+ " x vel:"
|
+ " x vel:"
|
||||||
+ String(round(parent.velocity.x))
|
+ String(round(parent.velocity.x))
|
||||||
+ " y vel/10:"
|
+ " y vel/10:"
|
||||||
+ String(round(parent.velocity.y/10))
|
+ String(round(parent.velocity.y / 10))
|
||||||
)
|
)
|
||||||
var new_state
|
var new_state
|
||||||
if !parent.is_on_floor():
|
if !parent.is_on_floor():
|
||||||
@ -123,10 +123,7 @@ func _get_transition(_delta):
|
|||||||
|
|
||||||
if parent.velocity.y >= 0:
|
if parent.velocity.y >= 0:
|
||||||
new_state = states.fall
|
new_state = states.fall
|
||||||
if (
|
if parent.is_touching_wall_completely():
|
||||||
parent.is_touching_wall_completely()
|
|
||||||
&& parent.velocity.y <= parent.wallslide_threshold
|
|
||||||
):
|
|
||||||
new_state = states.wallslide
|
new_state = states.wallslide
|
||||||
# Begins coyote time only if walking from ledge
|
# Begins coyote time only if walking from ledge
|
||||||
elif [states.walk, states.run].has(self.state) && !coyote_hanging:
|
elif [states.walk, states.run].has(self.state) && !coyote_hanging:
|
||||||
@ -162,7 +159,6 @@ func _get_transition(_delta):
|
|||||||
|
|
||||||
func _enter_state(new_state, old_state):
|
func _enter_state(new_state, old_state):
|
||||||
if old_state == "idle" && (new_state == "walk" || new_state == "run"):
|
if old_state == "idle" && (new_state == "walk" || new_state == "run"):
|
||||||
|
|
||||||
init_boost = true
|
init_boost = true
|
||||||
init_boost_type = old_state + "_" + new_state
|
init_boost_type = old_state + "_" + new_state
|
||||||
|
|
||||||
@ -182,7 +178,7 @@ func _enter_state(new_state, old_state):
|
|||||||
anim_player.play("idling")
|
anim_player.play("idling")
|
||||||
anim_player.queue("falling")
|
anim_player.queue("falling")
|
||||||
states.run:
|
states.run:
|
||||||
anim_player.play("walking",-1, 1.33)
|
anim_player.play("walking", -1, 1.33)
|
||||||
|
|
||||||
|
|
||||||
func _exit_state(old_state, new_state):
|
func _exit_state(old_state, new_state):
|
||||||
|
|||||||
@ -8,23 +8,23 @@ var stomp_feedback := 1000.0
|
|||||||
var inair_velocity := 21
|
var inair_velocity := 21
|
||||||
var wallslide_threshold := 1000
|
var wallslide_threshold := 1000
|
||||||
# TODO Map to floor types and move to physics constants
|
# TODO Map to floor types and move to physics constants
|
||||||
var normal_floor_friction := 1
|
var normal_floor_friction := 0.5
|
||||||
var max_velocity := {
|
var max_velocity := {
|
||||||
"walk": 120, "run": 160, "fall": 420, "walljump": 200, "idle": 12000
|
"walk": 120, "run": 160, "fall": 420, "walljump": 200, "idle": 12000
|
||||||
}
|
}
|
||||||
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 := {
|
var init_acceleration_force := {
|
||||||
"idle_walk": 4181/2, "idle_run": 5765/2, "walk_run": 1000/2
|
"idle_walk": 4181, "idle_run": 5765, "walk_run": 1000
|
||||||
}
|
}
|
||||||
# Oriented around deltas of 0.0166666...s
|
# Oriented around deltas of 0.0166666...s
|
||||||
# newtonmeters is the unit
|
# newtonmeters is the unit
|
||||||
var acceleration_force := {
|
var acceleration_force := {
|
||||||
"walk": Vector2(1000, 148000),
|
"walk": Vector2(1800, 1233),
|
||||||
"idle": Vector2(1000, 148000),
|
"idle": Vector2(1800, 1233),
|
||||||
"run": Vector2(1400, 148000),
|
"run": Vector2(2500, 1290),
|
||||||
"walljump": Vector2(72000, 126000),
|
"walljump": Vector2(600, 1050),
|
||||||
"air_strafe": Vector2(40000, 2000)
|
"air_strafe": Vector2(333, 2000)
|
||||||
}
|
}
|
||||||
# Gravity as m/s^2
|
# Gravity as m/s^2
|
||||||
var _gravity: float = PhysicsConst.gravity
|
var _gravity: float = PhysicsConst.gravity
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user