--Calculates an angle in relation to another part.

function core.findAngle(pos1,pos2,part)
	local yOrientation = part.Orientation.Y
	local rot = math.atan2(pos2.Z-pos1.Z, pos2.X-pos1.X)


	local desiredAngle = math.deg(rot)+yOrientation+90
	if desiredAngle > 180 then
		desiredAngle = -(360-desiredAngle)
	elseif desiredAngle <-180 then
		desiredAngle = 360+desiredAngle
	end	

	return desiredAngle
end

function core.findPitch(pos1,pos2,part)
	local xOrientation = part.Orientation.X
	local rot = math.atan2(pos2.Y-pos1.Y, math.abs(pos2.Z-pos1.Z))
	
	local desiredAngle = math.deg(rot)+xOrientation
	if desiredAngle > 180 then
		desiredAngle = -(360-desiredAngle)
	elseif desiredAngle <-180 then
		desiredAngle = 360+desiredAngle
	end	

	return desiredAngle
end

function core.tempAttach(pos,life)
	local attach = Instance.new("Attachment")
	attach.WorldPosition = pos
	attach.Parent = workspace.Terrain
	
	debrisService:AddItem(attach,life)
	
	return attach
end

function core.playSound(sound,pos)
	local attach = core.tempAttach(pos,sound.TimeLength)
	local soundClone = sound:Clone()
	soundClone.Parent = attach
	soundClone:Play()
end




return core
