23 lines
673 B
GDScript
23 lines
673 B
GDScript
class_name Groove
|
|
extends CharacterBody2D
|
|
|
|
|
|
@export var rest_length: float
|
|
@export var springiness: float
|
|
@export var damping: float
|
|
@export var player: Player
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var length = global_position.distance_to(player.global_position)
|
|
var tension = length - rest_length
|
|
if tension > 0:
|
|
var force = tension * springiness
|
|
velocity += global_position.direction_to(player.global_position) * force * delta
|
|
velocity -= velocity * damping * delta
|
|
move_and_slide()
|
|
|
|
|
|
func _on_hitbox_body_entered(body: Node2D) -> void:
|
|
if body.has_method(&"knock"):
|
|
body.knock(global_position.direction_to(body.global_position) * velocity.length())
|