baloon = {}

function baloonInit()
	baloon.body = FindBody("balloon")
	baloon.transform = GetBodyTransform(baloon.body)
	baloon.basket = FindBody("basket")
	SetBodyDynamic(baloon.basket, true)
	SetBodyActive(baloon.basket, true)

	-- baloon.mainRotor = FindBody("mainrotor")
	-- baloon.mainRotorLocalTransform = TransformToLocalTransform(baloon.transform, GetBodyTransform(baloon.mainRotor))

	-- baloon.tailRotor = FindBody("tailrotor")
	-- baloon.tailRotorLocalTransform = TransformToLocalTransform(baloon.transform, GetBodyTransform(baloon.tailRotor))

	baloon.searchLight = FindBody("light")
	baloon.searchLightLocalTransform = TransformToLocalTransform(baloon.transform, GetBodyTransform(baloon.searchLight))

	--baloon.sound = LoadLoop("baloon-loop.ogg")

	baloon.angle = 0.0
end


function baloonTick(dt, pos, aimPos, lightAimPos)
	baloon.angle = baloon.angle + 36*dt

	local diff = VecSub(aimPos, pos)
	diff[2] = 0
	local rot = QuatLookAt(pos, VecAdd(pos, diff))
	rot = QuatRotateQuat(rot, QuatEuler(math.sin(baloon.angle*0.053)*10, math.sin(baloon.angle*0.04)*10, 0))

	baloon.transform.pos = pos
	--baloon.transform.rot = rot
	SetBodyTransform(baloon.body, baloon.transform)

	-- baloon.mainRotorLocalTransform.rot = QuatEuler(0, baloon.angle*57, 0)
	-- SetBodyTransform(baloon.mainRotor, TransformToParentTransform(baloon.transform, baloon.mainRotorLocalTransform))

	-- baloon.tailRotorLocalTransform.rot = QuatEuler(baloon.angle*57, 0, 0)
	-- SetBodyTransform(baloon.tailRotor, TransformToParentTransform(baloon.transform, baloon.tailRotorLocalTransform))

	local lp = TransformToLocalPoint(baloon.transform, lightAimPos)
	baloon.searchLightLocalTransform.rot = QuatLookAt(baloon.searchLightLocalTransform.pos, lp)
	SetBodyTransform(baloon.searchLight, TransformToParentTransform(baloon.transform, baloon.searchLightLocalTransform))

	--PlayLoop(baloon.sound, baloon.transform.pos, 10)
end


