--Disable target if broken

lastVel = 0
fallTimer = 0


function init()
	target = FindBody("target")
	local bs = GetBodyShapes(target)
	if #bs == 1 then
		shape = bs[1]
	else
		shape = 0
		DebugPrint(GetTranslatedStringByKey("EXPLOSIVE_TARGET"))
	end
	done = false
end

function tick(dt)
	if not done then
		if IsShapeBroken(shape) then
			SetTag(target, "target", "disabled")
			SetString("hud.notification", GetTranslatedStringByKey("UI_HUD_NOTE_TARGET_EXPLODED"))
			done = true
		end

		local vel = VecLength(GetBodyVelocity(target))
		if lastVel > 8 then
			fallTimer = fallTimer + dt
			if fallTimer > 0.3 and vel < lastVel*0.6 then
				MakeHole(GetBodyTransform(target).pos, 0.2, 0.2)
			end
		else
			fallTimer = 0
		end	
		lastVel = vel
	end
end

