extends CharacterBody2D const MAGNET_FORCE = 100 func _ready(): add_to_group("magnets") max_slides = 1 func _physics_process(delta): var acceleration: Vector2 = Vector2() #calc direction for iter in get_tree().get_nodes_in_group("magnets"): if iter == self: continue acceleration += (iter.position - position).normalized() * MAGNET_FORCE #apply to velocity velocity += acceleration * delta var collided: bool = move_and_slide() if collided: velocity = Vector2.ZERO