extends RigidBody2D

func _physics_process(_delta):
	# This only works if Contact Monitor is ON and Max Contacts > 0
	var bodies = get_colliding_bodies()
	
	for body in bodies:
		if body is RigidBody2D:
			var dir = global_position.direction_to(body.global_position)
			var dist = global_position.distance_to(body.global_position)
			
			# Surface Tension: Pull them together if they are touching
			# We use a negative force to pull towards 'self'
			var strength = 200.0
			var force = -dir * strength * (1.0 - dist / 64.0)
			
			# Apply to the other body (or apply to self)
			body.apply_central_force(force)
