2024-02-22 00:10:13 -06:00
|
|
|
extends Sprite2D
|
|
|
|
|
|
|
|
@onready var player = $"../"
|
|
|
|
|
2024-02-24 12:12:57 -06:00
|
|
|
@onready var wallSlidingParticles = $"WallslidingParticles"
|
|
|
|
|
2024-02-22 00:10:13 -06:00
|
|
|
func spin(veloc, delta):
|
|
|
|
var vertSpinMult = abs(veloc.y) * clamp(veloc.x, -1, 1) / 1.5
|
2024-02-24 12:12:57 -06:00
|
|
|
var spinFactor = (veloc.x + vertSpinMult) / 30
|
2024-02-22 00:10:13 -06:00
|
|
|
|
|
|
|
if player.direction:
|
|
|
|
rotation = lerp(rotation, rotation + (spinFactor), delta)
|
|
|
|
else:
|
2024-02-24 12:12:57 -06:00
|
|
|
rotation = lerp(rotation, snappedf(rotation, PI / 2), delta * 10)
|
2024-02-22 00:10:13 -06:00
|
|
|
|
|
|
|
var landed = 0
|
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
var velocity = player.velocity
|
|
|
|
|
|
|
|
var floored = player.is_on_floor()
|
|
|
|
|
2024-02-24 12:12:57 -06:00
|
|
|
if player.is_on_wall_only() and velocity.y > 0:
|
|
|
|
wallSlidingParticles.emitting = true
|
|
|
|
wallSlidingParticles.global_position = player.position + (player.get_wall_normal() * -8)
|
|
|
|
wallSlidingParticles.global_rotation = player.get_wall_normal().x * deg_to_rad(45)
|
|
|
|
else:
|
|
|
|
wallSlidingParticles.emitting = false
|
2024-02-22 00:10:13 -06:00
|
|
|
|
|
|
|
if not floored:
|
|
|
|
spin(velocity, delta)
|
|
|
|
landed = velocity.y
|
|
|
|
|
|
|
|
scale = Vector2.ONE
|
2024-02-24 12:12:57 -06:00
|
|
|
|
|
|
|
if player.is_on_wall():
|
|
|
|
rotation = lerp(rotation, deg_to_rad(30) * player.get_wall_normal().x + snappedf(rotation, PI / 2), delta * 15)
|
2024-02-22 00:10:13 -06:00
|
|
|
else:
|
2024-02-24 12:12:57 -06:00
|
|
|
var floorRot = player.get_floor_normal().angle() + (PI / 2)
|
|
|
|
|
|
|
|
if abs(rotation - floorRot) > 0.9:
|
|
|
|
rotation = floorRot
|
|
|
|
|
|
|
|
rotation = lerp(rotation, floorRot, delta * 10)
|
2024-02-22 00:10:13 -06:00
|
|
|
|
|
|
|
if landed:
|
2024-02-24 12:12:57 -06:00
|
|
|
rotation = 0
|
2024-02-22 00:10:13 -06:00
|
|
|
scale.y = 1 - (landed / 800)
|
|
|
|
scale.x = 1 + (landed / 800)
|
|
|
|
landed = 0
|
|
|
|
|
2024-02-24 12:12:57 -06:00
|
|
|
scale.y = lerp(scale.y, 1.0, delta * 7)
|
|
|
|
scale.x = lerp(scale.x, 1.0, delta * 7)
|
|
|
|
|
|
|
|
scale.y = clamp(scale.y, 0.1, INF)
|
|
|
|
scale.x = clamp(scale.x, 0.1, INF)
|
|
|
|
|
2024-02-22 00:10:13 -06:00
|
|
|
offset.y = (8 * pow(scale.y, -1) - 8)
|
2024-02-24 12:12:57 -06:00
|
|
|
offset.x = 0
|