#include "script/common.lua"

function init()
	bodies = FindBodies()
	joints = FindJoints()
	target = FindBody("target")
	done = false
end

function tick(dt)
	if not done then
		local dist = VecLength(VecSub(GetCameraTransform().pos, GetBodyTransform(target).pos))
		local a = clamp(10 - dist, 0.0, 1.0)
		if a > 0.0 then
			for i=1, #bodies do
				DrawBodyOutline(bodies[i], 1, 1, 1, 0.5*a)
			end
		end
		if not IsHandleValid(target) then
			for i=1, #bodies do
				Delete(bodies[i])
			end
			for i=1, #joints do
				Delete(joints[i])
			end
			done = true
		end
	end
end

