|
|
|
|
@@ -63,20 +63,20 @@ static func process_movement(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func process_collision(
|
|
|
|
|
prev_velocity: Vector2,
|
|
|
|
|
new_velocity: Vector2,
|
|
|
|
|
slide_velocity: Vector2,
|
|
|
|
|
on_floor: bool,
|
|
|
|
|
on_ceiling: bool,
|
|
|
|
|
on_wall: bool,
|
|
|
|
|
wall_bounce_velocity_loss: float,
|
|
|
|
|
) -> Vector2:
|
|
|
|
|
if on_floor:
|
|
|
|
|
slide_velocity.x = 0
|
|
|
|
|
new_velocity = Vector2.ZERO
|
|
|
|
|
if on_ceiling:
|
|
|
|
|
slide_velocity.x *= wall_bounce_velocity_loss
|
|
|
|
|
new_velocity.x *= wall_bounce_velocity_loss
|
|
|
|
|
if on_wall:
|
|
|
|
|
slide_velocity.x = -new_velocity.x * wall_bounce_velocity_loss
|
|
|
|
|
return slide_velocity
|
|
|
|
|
new_velocity.x = -prev_velocity.x * wall_bounce_velocity_loss
|
|
|
|
|
return new_velocity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
@@ -129,33 +129,32 @@ func _physics_process(delta: float) -> void:
|
|
|
|
|
|
|
|
|
|
# apply velocity
|
|
|
|
|
velocity = new_velocity
|
|
|
|
|
var collision_occured := move_and_slide()
|
|
|
|
|
move_and_slide()
|
|
|
|
|
|
|
|
|
|
# collisions
|
|
|
|
|
if collision_occured:
|
|
|
|
|
var on_floor := not is_on_floor_prev and is_on_floor()
|
|
|
|
|
var on_ceiling := not is_on_ceiling_prev and is_on_ceiling()
|
|
|
|
|
var on_wall := (
|
|
|
|
|
not is_on_wall_prev
|
|
|
|
|
and is_on_wall()
|
|
|
|
|
and not is_on_floor()
|
|
|
|
|
and not is_zero_approx(new_velocity.x)
|
|
|
|
|
)
|
|
|
|
|
velocity = process_collision(
|
|
|
|
|
new_velocity,
|
|
|
|
|
velocity,
|
|
|
|
|
on_floor,
|
|
|
|
|
on_ceiling,
|
|
|
|
|
on_wall,
|
|
|
|
|
_wall_bounce_velocity_loss,
|
|
|
|
|
)
|
|
|
|
|
if on_floor:
|
|
|
|
|
_trajectory.visible = false
|
|
|
|
|
collided.emit(SIDE_BOTTOM, new_velocity)
|
|
|
|
|
if on_ceiling:
|
|
|
|
|
collided.emit(SIDE_TOP, new_velocity)
|
|
|
|
|
if on_wall:
|
|
|
|
|
collided.emit(SIDE_LEFT if velocity.x > 0 else SIDE_RIGHT, new_velocity)
|
|
|
|
|
var on_floor := not is_on_floor_prev and is_on_floor()
|
|
|
|
|
var on_ceiling := not is_on_ceiling_prev and is_on_ceiling()
|
|
|
|
|
var on_wall := (
|
|
|
|
|
not is_on_wall_prev
|
|
|
|
|
and is_on_wall()
|
|
|
|
|
and not is_on_floor()
|
|
|
|
|
and not is_zero_approx(new_velocity.x)
|
|
|
|
|
)
|
|
|
|
|
velocity = process_collision(
|
|
|
|
|
new_velocity,
|
|
|
|
|
velocity,
|
|
|
|
|
on_floor,
|
|
|
|
|
on_ceiling,
|
|
|
|
|
on_wall,
|
|
|
|
|
_wall_bounce_velocity_loss,
|
|
|
|
|
)
|
|
|
|
|
if on_floor:
|
|
|
|
|
_trajectory.visible = false
|
|
|
|
|
collided.emit(SIDE_BOTTOM, new_velocity)
|
|
|
|
|
if on_ceiling:
|
|
|
|
|
collided.emit(SIDE_TOP, new_velocity)
|
|
|
|
|
if on_wall:
|
|
|
|
|
collided.emit(SIDE_LEFT if velocity.x > 0 else SIDE_RIGHT, new_velocity)
|
|
|
|
|
|
|
|
|
|
queue_redraw()
|
|
|
|
|
|
|
|
|
|
|