local flying_timer = 0

addHook("PreThinkFrame", function()
	for player in players.iterate do
		if not (player.mo.skin == 'tails')
			return
		end
		
		if (player.mo.state == S_PLAY_FLY)
			flying_timer = flying_timer+1
			
			if flying_timer < 105 and player.mo.momz > (FRACUNIT*2) then
				player.mo.momz = player.mo.momz-(1*FRACUNIT)
			elseif flying_timer >= 105 and flying_timer < 210 and player.mo.momz > ((FRACUNIT*3/2)) then
				player.mo.momz = player.mo.momz-(1*FRACUNIT)
			else
				if flying_timer >= 210 and player.mo.momz > (FRACUNIT*1) then
					player.mo.momz = player.mo.momz-(1*FRACUNIT)
				end
			end
			
			if (player.mo.momx/FRACUNIT) > 16
				player.mo.momx = player.mo.momx-(1*FRACUNIT)
			end
			
			if (player.mo.momy/FRACUNIT) > 16
				player.mo.momy = player.mo.momy-(1*FRACUNIT)
			end
			
			if (player.mo.momx/FRACUNIT) < -16
				player.mo.momx = player.mo.momx+(1*FRACUNIT)
			end
			
			if (player.mo.momy/FRACUNIT) < -16
				player.mo.momy = player.mo.momy+(1*FRACUNIT)
			end		
		elseif (player.mo.state == S_PLAY_FLY_TIRED)
			flying_timer = 0
			
			if (player.mo.momx/FRACUNIT) > 20
				player.mo.momx = player.mo.momx-(1*FRACUNIT)
			end
			
			if (player.mo.momy/FRACUNIT) > 20
				player.mo.momy = player.mo.momy-(1*FRACUNIT)
			end
			
			if (player.mo.momx/FRACUNIT) < -20
				player.mo.momx = player.mo.momx+(1*FRACUNIT)
			end
			
			if (player.mo.momy/FRACUNIT) < -20
				player.mo.momy = player.mo.momy+(1*FRACUNIT)
			end
		else
			flying_timer = 0
		end
	end
end)