GrappleTest/Player/BasicCharacter/AnimationController.gd

120 lines
3.1 KiB
GDScript3
Raw Permalink Normal View History

2024-02-22 00:10:13 -06:00
extends Sprite2D
@onready var player = $"../"
2024-02-26 08:28:11 -06:00
var spinAccel = 0
2024-02-24 12:12:57 -06:00
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-27 11:27:54 -06:00
var spinFactor = (veloc.x + vertSpinMult) / 40
spinFactor = clamp(spinFactor, -25, 25)
2024-02-22 00:10:13 -06:00
2024-03-17 21:56:16 -05:00
if (player.direction or abs(player.velocity.x) > 100) and not player.is_on_wall():
2024-02-22 00:10:13 -06:00
rotation = lerp(rotation, rotation + (spinFactor), delta)
else:
2024-02-27 11:27:54 -06:00
rotation = lerp(rotation, snappedf(rotation + clamp(spinFactor * delta * 2, -PI / 3, PI / 3), PI / 2), delta * 5)
2024-02-22 00:10:13 -06:00
var landed = 0
2024-02-26 08:28:11 -06:00
@onready var slidingVariants = [$"WallslidingNeutral", $"WallslidingUp", $"WallslidingDown"]
2024-02-29 10:38:22 -06:00
var afterImage = preload("res://Particles/Player/AfterImage.tscn")
2024-02-26 08:28:11 -06:00
func disableSlidingVariants(keep=null):
for variant in slidingVariants:
if variant != keep:
variant.emitting = false
2024-02-29 10:38:22 -06:00
var imageTimer = 0
var imaging = false
var lastImage = Vector2.ZERO
2024-03-13 16:15:55 -05:00
func _ready():
if player.has_signal("Jumped"):
player.Jumped.connect(_on_character_jumped)
2024-02-22 00:10:13 -06:00
func _process(delta):
2024-02-29 10:38:22 -06:00
2024-02-22 00:10:13 -06:00
var velocity = player.velocity
var floored = player.is_on_floor()
2024-02-29 10:38:22 -06:00
if velocity.length() >= 1100:
imaging = true
elif velocity.length() < 800:
imaging = false
2024-03-13 16:15:55 -05:00
if (imaging or (find_child("Grapple") and $"Grapple".grappling)) and (global_position - lastImage).length() > 16:
2024-02-29 10:38:22 -06:00
var parti = afterImage.instantiate()
add_child(parti)
parti.duration = velocity.length() / 2000
lastImage = global_position
2024-02-26 08:28:11 -06:00
if player.isWallSliding():
var wallSlidingParticles = slidingVariants[0]
if abs(velocity.y) < 150:
wallSlidingParticles = slidingVariants[1]
elif abs(velocity.y) > 300:
wallSlidingParticles = slidingVariants[2]
disableSlidingVariants(wallSlidingParticles)
2024-02-24 12:12:57 -06:00
wallSlidingParticles.emitting = true
2024-02-26 08:28:11 -06:00
wallSlidingParticles.global_position = player.position + (player.get_wall_normal() * -8 * player.scale.x)
2024-02-24 12:12:57 -06:00
wallSlidingParticles.global_rotation = player.get_wall_normal().x * deg_to_rad(45)
2024-02-26 08:28:11 -06:00
2024-02-24 12:12:57 -06:00
else:
2024-02-26 08:28:11 -06:00
disableSlidingVariants()
2024-02-22 00:10:13 -06:00
if not floored:
2024-03-13 16:15:55 -05:00
if player.is_on_ceiling() and landed < -100:
rotation = 0
2024-03-17 21:56:16 -05:00
scale.y = 1 + (landed / 800.)
scale.x = 1 - (landed / 800.)
2024-03-13 16:15:55 -05:00
2024-02-22 00:10:13 -06:00
spin(velocity, delta)
landed = velocity.y
2024-02-26 08:28:11 -06:00
#scale = Vector2.ONE
2024-02-24 12:12:57 -06:00
2024-02-26 08:28:11 -06:00
if player.isWallSliding():
2024-02-24 12:12:57 -06:00
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-29 10:38:22 -06:00
if Input.is_action_just_pressed("down"):
scale.x = 2
scale.y *= 0.5
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)
2024-02-26 08:28:11 -06:00
scale.y = clamp(scale.y, 0.25, INF)
2024-02-24 12:12:57 -06:00
scale.x = clamp(scale.x, 0.1, INF)
2024-02-26 08:28:11 -06:00
#modulate.h = abs(player.position.x / 400.)
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
2024-02-26 08:28:11 -06:00
2024-03-13 16:15:55 -05:00
if find_child("Grapple"):
$"Grapple/GrappleCore".offset = offset
2024-02-26 08:28:11 -06:00
func _on_character_jumped():
if not player.direction:
rotation = 0
scale.y = 1.5
scale.x = 0.5
2024-03-13 16:15:55 -05:00
else:
scale = Vector2.ONE
offset = Vector2.ZERO