function init()
	local origin = FindLocation("origin")
	local origin_transform = GetLocationTransform(origin)
	local origin_pos = origin_transform.pos

	local direction = FindLocation("direction")
	local direction_transform = GetLocationTransform(direction)
	local direction_pos = direction_transform.pos

	boat = FindVehicle("boat")
	local boat_transform = GetVehicleTransform(boat)

	local_origin = TransformToLocalPoint(boat_transform, origin_pos)
	local_direction = TransformToLocalPoint(boat_transform, direction_pos)
end


--Helper to return a random vector of particular length
function rndVec(length)
	local v = VecNormalize(Vec(math.random(-100,100), math.random(-100,100), math.random(-100,100)))
	return VecScale(v, length)	
end


--Helper to return a random number in range mi to ma
function rnd(mi, ma)
	return math.random(1000)/1000*(ma-mi) + mi
end


--Update function handles smoke emission
--It is important to put it in update and not tick for constant emission rate
function update(dt)

	local boat_transform = GetVehicleTransform(boat)
	local world_origin = TransformToParentPoint(boat_transform,local_origin)
	local world_direction = TransformToParentPoint(boat_transform,local_direction)

	local pos = world_origin--t.pos
	local dir = VecSub(world_direction,world_origin)

	-- THINGS YOU CAN TWEAK

	-- radius, particle spawn randomness from origin in meters
	local radius = 0.2
	-- life, particle lifetime in seconds
	local life = rnd(2,12)
	
	-- amount of particles emitted every frame
	local count = 5
	-- velocity of the particles
	local vel = 2
	-- particle drag
	local drag = 0.1
	-- particle gravity
	local gravity = 0.12
	
	-- aplha of the particles, is also affected by the lifetime of the particle
	local alpha = 0.3

	-- Start values for the particle color
	local start_red = 0.1
	local start_green = 0.1
	local start_blue = 0.1
	
	-- End values for the particle color
	local end_red = 0.5
	local end_green = 0.5
	local end_blue = 0.5

	--Set up the particle state
	ParticleReset()
	ParticleType("smoke")
	ParticleRadius(radius)
	ParticleAlpha(alpha, alpha, "constant", 0.1/life, 0.5)	-- Ramp up fast, ramp down after 50%
	ParticleGravity(gravity * rnd(0.5, 1.5))				-- Slightly randomized gravity looks better
	ParticleDrag(drag)
	ParticleColor(start_red, start_green, start_blue, end_red, end_green, end_blue)			-- Animating color towards white
	
	--Emit particles
	for i=1, count do
		--Randomize position slightly. This is important when spawning multiple particles at the same time
		local p = VecAdd(pos, VecAdd(VecScale(dir, radius), rndVec(radius)))
		
		--Randomize velocity slightly
		local v = VecScale(VecAdd(dir, rndVec(0.2)), vel)
		
		--Randomize lifetime
		local l = rnd(life*0.5, life*1.5)

		--Spawn particle into the world
		SpawnParticle(p, v, l)
	end
end
